This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: urllib.request exposes too many names
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.3
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, flox, orsenthil, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2011-10-28 15:01 by flox, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue13287_urllib_request.diff flox, 2011-10-28 19:49 review
Messages (8)
msg146568 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-10-28 15:01
>>> len(dir())
>>> import urllib.request import *
>>> len(dir())

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.
msg146571 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-10-28 15:23
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.
msg146572 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-10-28 16:06
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
msg146576 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-10-28 19:49
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.
msg146781 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-01 15:20
New changeset 70dedd8ce8f3 by Senthil Kumaran in branch 'default':
issue13287 - Define __all__ for urllib.request and urllib.error and expose only
msg146782 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-11-01 15:28
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.
msg147025 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-11-04 19:15
test_urllib2.test___all__() is failing on Windows. Example:

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\", 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'

msg147040 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-04 21:15
New changeset ca78ed7393bf by Florent Xicluna in branch 'default':
Fix test_urllib2 error on Windows in relation with issue #13287.
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57496
2011-11-04 21:17:12floxsetstatus: open -> closed
2011-11-04 21:15:58python-devsetmessages: + msg147040
2011-11-04 19:15:50vstinnersetstatus: closed -> open

nosy: + vstinner
messages: + msg147025

resolution: fixed ->
2011-11-01 15:28:44orsenthilsetstatus: open -> closed
resolution: fixed
messages: + msg146782
2011-11-01 15:20:51python-devsetnosy: + python-dev
messages: + msg146781
2011-10-28 19:49:13floxsetfiles: + issue13287_urllib_request.diff
keywords: + patch
messages: + msg146576

stage: needs patch -> patch review
2011-10-28 16:06:38orsenthilsetmessages: + msg146572
2011-10-28 15:23:33ezio.melottisetnosy: + ezio.melotti
messages: + msg146571
2011-10-28 15:11:14pitrousetnosy: + orsenthil
2011-10-28 15:01:14floxcreate