Skip to content

Commit 38e19bd

Browse files
committed
Deprecate __version__ attribute
1 parent 1acb718 commit 38e19bd

29 files changed

+301
-27
lines changed

Doc/deprecations/pending-removal-in-3.17.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,24 @@ Pending removal in Python 3.17
88
but it has been retained for backward compatibility, with removal scheduled for Python
99
3.17. Users should use documented introspection helpers like :func:`typing.get_origin`
1010
and :func:`typing.get_args` instead of relying on private implementation details.
11+
12+
* The ``__version__`` attribute has been deprecated in these standard library
13+
modules and will be removed in Python 3.17.
14+
Use :py:data:`sys.version_info` instead.
15+
16+
- :mod:`argparse`
17+
- :mod:`csv`
18+
- :mod:`!ctypes.macholib`
19+
- :mod:`ipaddress`
20+
- :mod:`json`
21+
- :mod:`logging` (``__date__`` also deprecated)
22+
- :mod:`optparse`
23+
- :mod:`pickle`
24+
- :mod:`platform`
25+
- :mod:`re`
26+
- :mod:`socketserver`
27+
- :mod:`tabnanny`
28+
- :mod:`tkinter.font`
29+
- :mod:`tkinter.ttk`
30+
31+
(Contributed by Hugo van Kemenade in :gh:`76007`.)

Doc/whatsnew/3.15.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,40 @@ hashlib
550550

551551
(Contributed by Bénédikt Tran in :gh:`134978`.)
552552

553+
__version__
554+
-----------
555+
556+
* The ``__version__`` attribute has been deprecated in these standard library
557+
modules and will be removed in Python 3.17.
558+
Use :py:data:`sys.version_info` instead.
559+
560+
- :mod:`argparse`
561+
- :mod:`csv`
562+
- :mod:`!ctypes.macholib`
563+
- :mod:`ipaddress`
564+
- :mod:`json`
565+
- :mod:`logging` (``__date__`` also deprecated)
566+
- :mod:`optparse`
567+
- :mod:`pickle`
568+
- :mod:`platform`
569+
- :mod:`re`
570+
- :mod:`socketserver`
571+
- :mod:`tabnanny`
572+
- :mod:`tkinter.font`
573+
- :mod:`tkinter.ttk`
574+
575+
(Contributed by Hugo van Kemenade in :gh:`76007`.)
553576

554577
.. Add deprecations above alphabetically, not here at the end.
555578
579+
.. include:: ../deprecations/pending-removal-in-3.16.rst
580+
581+
.. include:: ../deprecations/pending-removal-in-3.17.rst
582+
583+
.. include:: ../deprecations/pending-removal-in-3.19.rst
584+
585+
.. include:: ../deprecations/pending-removal-in-future.rst
586+
556587
Removed
557588
=======
558589

Lib/argparse.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
still considered an implementation detail.)
6565
"""
6666

67-
__version__ = '1.1'
6867
__all__ = [
6968
'ArgumentParser',
7069
'ArgumentError',
@@ -2773,3 +2772,12 @@ def error(self, message):
27732772
def _warning(self, message):
27742773
args = {'prog': self.prog, 'message': message}
27752774
self._print_message(_('%(prog)s: warning: %(message)s\n') % args, _sys.stderr)
2775+
2776+
2777+
def __getattr__(name):
2778+
if name == "__version__":
2779+
from warnings import _deprecated
2780+
2781+
_deprecated("__version__", remove=(3, 17))
2782+
return "1.1" # Do not change
2783+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/csv.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class excel:
8181
"unregister_dialect", "DictReader", "DictWriter",
8282
"unix_dialect"]
8383

84-
__version__ = "1.0"
85-
8684

8785
class Dialect:
8886
"""Describe a CSV dialect.
@@ -511,3 +509,12 @@ def has_header(self, sample):
511509
hasHeader -= 1
512510

513511
return hasHeader > 0
512+
513+
514+
def __getattr__(name):
515+
if name == "__version__":
516+
from warnings import _deprecated
517+
518+
_deprecated("__version__", remove=(3, 17))
519+
return "1.0" # Do not change
520+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/ctypes/macholib/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
And also Apple's documentation.
77
"""
88

9-
__version__ = '1.0'
9+
def __getattr__(name):
10+
if name == "__version__":
11+
from warnings import _deprecated
12+
13+
_deprecated("__version__", remove=(3, 17))
14+
return "1.0" # Do not change
15+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/ipaddress.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
99
"""
1010

11-
__version__ = '1.0'
12-
13-
1411
import functools
1512

1613
IPV4LENGTH = 32
@@ -2419,3 +2416,12 @@ class _IPv6Constants:
24192416

24202417
IPv6Address._constants = _IPv6Constants
24212418
IPv6Network._constants = _IPv6Constants
2419+
2420+
2421+
def __getattr__(name):
2422+
if name == "__version__":
2423+
from warnings import _deprecated
2424+
2425+
_deprecated("__version__", remove=(3, 17))
2426+
return "1.0" # Do not change
2427+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/json/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
$ echo '{ 1.2:3.4}' | python -m json
9696
Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
9797
"""
98-
__version__ = '2.0.9'
9998
__all__ = [
10099
'dump', 'dumps', 'load', 'loads',
101100
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
@@ -357,3 +356,12 @@ def loads(s, *, cls=None, object_hook=None, parse_float=None,
357356
if parse_constant is not None:
358357
kw['parse_constant'] = parse_constant
359358
return cls(**kw).decode(s)
359+
360+
361+
def __getattr__(name):
362+
if name == "__version__":
363+
from warnings import _deprecated
364+
365+
_deprecated("__version__", remove=(3, 17))
366+
return "2.0.9" # Do not change
367+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/logging/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545

4646
__author__ = "Vinay Sajip <[email protected]>"
4747
__status__ = "production"
48-
# The following module attributes are no longer updated.
49-
__version__ = "0.5.1.2"
50-
__date__ = "07 February 2010"
5148

5249
#---------------------------------------------------------------------------
5350
# Miscellaneous module data
@@ -2341,3 +2338,16 @@ def captureWarnings(capture):
23412338
if _warnings_showwarning is not None:
23422339
warnings.showwarning = _warnings_showwarning
23432340
_warnings_showwarning = None
2341+
2342+
2343+
def __getattr__(name):
2344+
if name in ("__version__", "__date__"):
2345+
from warnings import _deprecated
2346+
2347+
_deprecated(name, remove=(3, 17))
2348+
return { # Do not change
2349+
"__version__": "0.5.1.2",
2350+
"__date__": "07 February 2010",
2351+
}[name]
2352+
2353+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/optparse.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
(options, args) = parser.parse_args()
2222
"""
2323

24-
__version__ = "1.5.3"
25-
2624
__all__ = ['Option',
2725
'make_option',
2826
'SUPPRESS_HELP',
@@ -1669,3 +1667,12 @@ def _match_abbrev(s, wordmap):
16691667
# which will become a factory function when there are many Option
16701668
# classes.
16711669
make_option = Option
1670+
1671+
1672+
def __getattr__(name):
1673+
if name == "__version__":
1674+
from warnings import _deprecated
1675+
1676+
_deprecated("__version__", remove=(3, 17))
1677+
return "1.5.3" # Do not change
1678+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/pickle.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
1818
Misc variables:
1919
20-
__version__
2120
format_version
2221
compatible_formats
2322

0 commit comments

Comments
 (0)