Skip to content

urllib.request exposes too many names #57496

Closed

Description

@florentx
mannequin
BPO 13287
Nosy @orsenthil, @vstinner, @ezio-melotti, @florentx
Files
  • issue13287_urllib_request.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-11-04.21:17:12.268>
    created_at = <Date 2011-10-28.15:01:14.920>
    labels = ['type-bug', 'library']
    title = 'urllib.request exposes too many names'
    updated_at = <Date 2011-11-04.21:17:12.267>
    user = 'https://github.com/florentx'

    bugs.python.org fields:

    activity = <Date 2011-11-04.21:17:12.267>
    actor = 'flox'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-11-04.21:17:12.268>
    closer = 'flox'
    components = ['Library (Lib)']
    creation = <Date 2011-10-28.15:01:14.920>
    creator = 'flox'
    dependencies = []
    files = ['23543']
    hgrepos = []
    issue_num = 13287
    keywords = ['patch']
    message_count = 8.0
    messages = ['146568', '146571', '146572', '146576', '146781', '146782', '147025', '147040']
    nosy_count = 5.0
    nosy_names = ['orsenthil', 'vstinner', 'ezio.melotti', 'flox', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13287'
    versions = ['Python 3.3']

    Activity

    1. florentx commented on Oct 28, 2011

      florentxmannequin
      MannequinAuthor
      >>> len(dir())
      4
      >>> import urllib.request import *
      >>> len(dir())
      88

      In this list we find 14 modules:
      ['base64', 'collections', 'ssl', 'bisect', 'http', 're', 'email', 'socket', 'os', 'posixpath', 'hashlib', 'io', 'time', 'sys']

      And many non-documented functions:

      • ftperrors
      • getproxies_environment
      • getproxies_macosx_sysconf
      • localhost
      • noheaders
      • parse_http_list
      • parse_keqv_list
      • proxy_bypass
      • proxy_bypass_environment
      • proxy_bypass_macosx_sysconf
      • quote
      • randombytes
      • request_host
      • urlunparse
      • splitattr
      • splithost
      • splitpasswd
      • splitport
      • splitquery
      • splittag
      • splittype
      • splituser
      • splitvalue
      • thishost
      • to_bytes
      • unquote
      • unwrap
      • urljoin
      • urlparse
      • urlsplit

      It may be good to define __all__ for this module, and to preprend "_" on some of these names.

    2. added
      stdlib
      type-bug
      on Oct 28, 2011
    3. ezio-melotti commented on Oct 28, 2011

      @ezio-melotti
      Member

      This is technically backward incompatible, so if we define an __all__ with most of these names, we are officially making them public, if we leave them out, from urllib.request import * will break for someone.
      You could argue that import * is discouraged though.

    4. orsenthil commented on Oct 28, 2011

      @orsenthil
      Member

      Let's deprecate some of these (or add deprecation warnings) for
      upcoming release. But, doing from xxx import * is not a recommended
      way for any module, as we know that it stands to pollute the namespace
      with unneccesary functions/methods. I would be careful in adding
      anything to __all__ and if done, may go for only 3.3. Ezio has a valid
      point.

    5. florentx commented on Oct 28, 2011

      florentxmannequin
      MannequinAuthor

      We should only expose the names which are documented.
      The modules and the objects from urllib.parse don't need to be exposed in urllib.request.

      I suggest to apply this patch on 3.3 only.

    6. python-dev commented on Nov 1, 2011

      python-devmannequin
      Mannequin

      New changeset 70dedd8ce8f3 by Senthil Kumaran in branch 'default':
      bpo-13287 - Define __all__ for urllib.request and urllib.error and expose only
      http://hg.python.org/cpython/rev/70dedd8ce8f3

    7. orsenthil commented on Nov 1, 2011

      @orsenthil
      Member

      Thanks flox for the patch.

      Just the News item is added. I don't think, this requires any Docs update. One change I had to make in the patch is to remote HTTPSHandler from __all__ because that is only conditionally available when http.client supports HTTPSConnection. Neither might this require a docs update because Handlers may be used only within urllib.request namespace and not standalone.

    8. vstinner commented on Nov 4, 2011

      @vstinner
      Member

      test_urllib2.test___all__() is failing on Windows. Example:

      http://www.python.org/dev/buildbot/all/builders/x86%20XP-4%203.x/builds/5498/steps/test/logs/stdio

      ======================================================================
      FAIL: test___all__ (test.test_urllib2.TrivialTests)
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_urllib2.py", line 32, in test___all__
          (k, module, v.__module__))
      AssertionError: 'nturl2path' != 'urllib.request'
      - nturl2path
      + urllib.request
       : 'pathname2url' is exposed in 'urllib.request' but defined in 'nturl2path'

    9. python-dev commented on Nov 4, 2011

      python-devmannequin
      Mannequin

      New changeset ca78ed7393bf by Florent Xicluna in branch 'default':
      Fix test_urllib2 error on Windows in relation with issue bpo-13287.
      http://hg.python.org/cpython/rev/ca78ed7393bf

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions