Repository navigation
Misleading __version__ attribute of modules in standard library #76007
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 31826 |
|---|---|
| Nosy | @warsaw, @rhettinger, @ncoghlan, @pitrou, @merwok, @encukou, @serhiy-storchaka, @abukaj, @cryvate |
| PRs |
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 = None
created_at = <Date 2017-10-20.13:21:04.010>
labels = ['3.7', 'type-bug', 'library']
title = 'Misleading __version__ attribute of modules in standard library'
updated_at = <Date 2020-02-04.10:54:36.743>
user = 'https://github.com/abukaj'bugs.python.org fields:
activity = <Date 2020-02-04.10:54:36.743>
actor = 'cryvate'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2017-10-20.13:21:04.010>
creator = 'abukaj'
dependencies = []
files = []
hgrepos = []
issue_num = 31826
keywords = ['patch']
message_count = 7.0
messages = ['304654', '304763', '304765', '304779', '304780', '304823', '361340']
nosy_count = 9.0
nosy_names = ['barry', 'rhettinger', 'ncoghlan', 'pitrou', 'eric.araujo', 'petr.viktorin', 'serhiy.storchaka', 'abukaj', 'cryvate']
pr_nums = ['17977']
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue31826'
versions = ['Python 3.7']Linked PRs
- gh-76007: Deprecate
__version__attribute #138675 - gh-76007:
pydoc: CatchDeprecationWarningfor stdlib module__version__attributes #139997 - gh-76007: Deprecate
zlib.__version__attribute #140130 - gh-76007: Deprecate
__version__attribute inimaplib#140299 - gh-76007: Deprecate
__version__attribute indecimal#140302 - gh-76007: remove curses.__version__ doc #141052
- [3.14] gh-76007: remove curses.__version__ doc (GH-141052) #141076
- [3.13] gh-76007: remove curses.__version__ doc (GH-141052) #141077
- gh-76007: Deprecate
__version__attribute inhttp.server#142658 - gh-76007: Deprecate
__version__attribute inwsgiref.simple_server#142675 - gh-76007: Deprecate
__version__attribute inctypes#142679 - gh-76007: Deprecate
VERSIONinxml.etree.ElementTree&versioninxml.sax.expatreader&xml.sax.handler#142898 - gh-76007: Deprecate
tarfile.version#145326
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
hugovk commentedon Sep 8, 2025
Please see #138675 to take care of the straightforward Python modules.
To follow up: there's some Python ones which use
__version__internally, but some of these can also be deprecated. And there's some C modules to also check.warsaw commentedon Sep 8, 2025
__version__is used insmtpd.pyas the response banner. That should probably just beplatform.python_version().picnixz commentedon Sep 8, 2025
Ah yes, I'd like the version in
imaplibto be gone. I actually bumped the version in main but there were differences between main and 3.14 (or 3.13 I don't remember) but a bugfix actually was needed for both so they were out of sync (in one branch we had version x.y.z, while in the other we had x.y.(z-1), but the bugfix bumped them both...)hugovk commentedon Sep 9, 2025
Other non-test
__version__s inLib/:-> Commented, and needs to stay.
-> Edit: done in python/cpython#140302 ✅
-> Ensures the version matches that in
_ctypes.c. I think both can be deprecated this version check removed in 3.15?-> Edit: PR at python/cpython#142679
-> Only used in this function:
Which is set in the response header:
Perhaps these can also be deprecated?
-> Edit: done in python/cpython#142658 ✅
-> Only used in debugging, I think
__version__is fine for deprecation. And we could remove this debug already in 3.15?-> Edit: done in python/cpython#140299 ✅
-> Edit: Can stay.
-> Set here:
OK to deprecate
__version__and changeserver_versiontof"WSGIServer/{sys_version}"in 3.15?-> Edit: PR at python/cpython#142675
-> Edit: Can stay.
picnixz commentedon Sep 9, 2025
Well... actually for urllib, we have the following docs:
So we need to keep it (or document that has now a different form?) I don't think there is a difference between using sys.version_info and platform.python_version here.
For XMLRPC, I think it's fine to change it as we can override it. We should change the default value use
sys.version_infoprobably. For WSI, since it's a simple server, let's do the same as well. Same for http.server, we should just match the server version with the Python version. Maybe for parsing purposes, I would suggest that we keep BaseHTTP/version:Python/version as it's documented in https://docs.python.org/3/library/http.server.html#http.server.BaseHTTPRequestHandler.server_version.For imaplib, I can just deprecate it in 3.14 and remove in 3.15. I don't think anyone has ever relied on it. Also the version depends on the underlying Python version so having the Python version is much more useful.
hugovk commentedon Sep 9, 2025
It's too late to deprecate in 3.14, do you mean deprecate in 3.15? And we're in no rush to remove these, we can stick to the usual two-release policy for removing (so in 3.17).
picnixz commentedon Sep 9, 2025
Oh sorry I misunderstood the "And we could remove this debug already in 3.15?" by assuming you wanted to remove the version as well. I'm fine with deprecating them in 3.15 and removing it in 3.17.
smontanaro commentedon Sep 9, 2025
@hugovk wrote:
This seems like a poor name to me. Can it change to, say,
__spec_version__so people who come along later don't think it's the module version.merwok commentedon Sep 9, 2025
Yes, let’s avoid dunders for things that are not actually defined by the Python documentation.
smontanaro commentedon Sep 9, 2025
Thanks, even better,
SPEC_VERSION?gh-76007: Deprecate `__version__` attribute (#138675)
StanFromIreland commentedon Oct 12, 2025
@hugovk , the deprecation causes warnings to be raised by pydoc:
Should we just remove the handling of
__version__since it is scheduled for removal anyway, or catch the warnings for now? (I propose the first).pitrou commentedon Oct 12, 2025
Eh?
pydocis meant to work with all kinds of modules, not just stdlib modules.StanFromIreland commentedon Oct 12, 2025
Just for stdlib modules, we similarly gate the docs.python.org link generation.
picnixz commentedon Oct 12, 2025
Do you mean to catch the warning only for stdlib modules? if so, why not (because we special case the stdlib for the link), otherwise I agree that pydoc is a general tool.
StanFromIreland commentedon Oct 12, 2025
Yes. I wrote #139997 for this, reusing the logic from
getdoclink.StanFromIreland commentedon Oct 14, 2025
I see
zlib.__version__was not deprecated, and I see no mention in this issue as to why, so I assume it was missed. I will open a pr.gh-76007: Deprecate `zlib.__version__` attribute (#140130)
gh-76007: Deprecate `__version__` attribute in `imaplib` (#140299)
onerandomusername commentedon Oct 26, 2025
Noticed another
__version__:http.server.__version__doesn't seem to have been deprecated.Looking into it, it seems to be used by the
http.server.SimpleHTTPRequestHandler.server_versionattribute.cpython/Lib/http/server.py
Line 64 in 421a475
I would be willing to make this pull request, following the deprecation guidelines and module level getattr.
My question is as follows: should the
server_versiondefault be changed to be the first two of sys.version_info?Should this adjustment happen with 3.15? Or wait until 3.20?
picnixz commentedon Oct 26, 2025
onerandomusername commentedon Oct 26, 2025
picnixz commentedon Oct 26, 2025
[Oh my bad, I was on mobile and thought you were talking about the class' version]. I don't really know which would be the best but if it hadn't been changed for years, it's better to get rid of it. However, whatever we choose here should be done for XMLRPC and other modules that provide simple servers or handlers as they essentially do the same. This would require a bit more work as we would need to change the docs as well.
curses.__version__documented but does not exist #140606 as a duplicate of this issuegh-76007: Deprecate `__version__` attribute in `decimal` (#140302)
vstinner commentedon Oct 26, 2025
IMO it's a good idea to use the Python version as the HTTP server version.
gh-76007: remove curses.__version__ doc (#141052)
pythongh-76007: remove curses.__version__ doc (pythonGH-141052)
pythongh-76007: remove curses.__version__ doc (pythonGH-141052)
[3.14] gh-76007: remove curses.__version__ doc (GH-141052) (#141076)
[3.13] gh-76007: remove curses.__version__ doc (GH-141052) (#141077)
pythongh-76007: Deprecate `zlib.__version__` attribute (python#140130)
pythongh-76007: Deprecate `__version__` attribute in `imaplib` (pytho…
pythongh-76007: Deprecate `__version__` attribute in `decimal` (pytho…
pythongh-76007: remove curses.__version__ doc (python#141052)
gh-76007: Deprecate `__version__` attribute in `http.server` (#142658)
gh-76007: `pydoc`: Catch `DeprecationWarning` for stdlib module `__ve…
hugovk commentedon Dec 14, 2025
I think we're done with
__version__once #142675 and #142679 are merged, or are there any more to do?There's also a
VERSIONand a couple ofversions we could deprecate:cpython/Lib/xml/etree/ElementTree.py
Line 93 in 04da416
cpython/Lib/xml/sax/expatreader.py
Line 6 in 04da416
cpython/Lib/xml/sax/handler.py
Line 12 in 04da416
Thoughts?
gh-76007: Deprecate `__version__` attribute in `ctypes` (#142679)
pythongh-76007: `pydoc`: Catch `DeprecationWarning` for stdlib module…
pythongh-76007: Deprecate `__version__` attribute in `ctypes` (python…
gh-76007: Deprecate `__version__` attribute in `wsgiref.simple_server` (
hugovk commentedon Dec 17, 2025
PR #142898 for that, to close this issue.
gh-76007: Deprecate `VERSION` in `xml.etree.ElementTree` & `version` …
pythongh-76007: Deprecate `VERSION` in `xml.etree.ElementTree` & `ver…
gh-76007: Deprecate `tarfile.version` (#145326)
pythongh-76007: Deprecate `tarfile.version` (python#145326)
pythongh-76007: Deprecate `tarfile.version` (python#145326)