Skip to content

Commit 872eafd

Browse files
hugovkaiskencukou
authored
gh-76007: Deprecate __version__ attribute (#138675)
Co-authored-by: AN Long <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
1 parent 408154d commit 872eafd

34 files changed

+320
-29
lines changed

Doc/deprecations/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Deprecations
99

1010
.. include:: pending-removal-in-3.19.rst
1111

12+
.. include:: pending-removal-in-3.20.rst
13+
1214
.. include:: pending-removal-in-future.rst
1315

1416
C API deprecations
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Pending removal in Python 3.20
2+
------------------------------
3+
4+
* The ``__version__`` attribute has been deprecated in these standard library
5+
modules and will be removed in Python 3.20.
6+
Use :py:data:`sys.version_info` instead.
7+
8+
- :mod:`argparse`
9+
- :mod:`csv`
10+
- :mod:`!ctypes.macholib`
11+
- :mod:`ipaddress`
12+
- :mod:`json`
13+
- :mod:`logging` (``__date__`` also deprecated)
14+
- :mod:`optparse`
15+
- :mod:`pickle`
16+
- :mod:`platform`
17+
- :mod:`re`
18+
- :mod:`socketserver`
19+
- :mod:`tabnanny`
20+
- :mod:`tkinter.font`
21+
- :mod:`tkinter.ttk`
22+
23+
(Contributed by Hugo van Kemenade in :gh:`76007`.)

Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,10 @@ Deprecated
13631363

13641364
.. include:: ../deprecations/pending-removal-in-3.17.rst
13651365

1366+
.. include:: ../deprecations/pending-removal-in-3.19.rst
1367+
1368+
.. include:: ../deprecations/pending-removal-in-3.20.rst
1369+
13661370
.. include:: ../deprecations/pending-removal-in-future.rst
13671371

13681372
.. _whatsnew312-removed:

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,10 @@ New Deprecations
20262026

20272027
.. include:: ../deprecations/pending-removal-in-3.17.rst
20282028

2029+
.. include:: ../deprecations/pending-removal-in-3.19.rst
2030+
2031+
.. include:: ../deprecations/pending-removal-in-3.20.rst
2032+
20292033
.. include:: ../deprecations/pending-removal-in-future.rst
20302034

20312035
CPython Bytecode Changes

Doc/whatsnew/3.14.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,8 @@ Deprecated
27942794

27952795
.. include:: ../deprecations/pending-removal-in-3.19.rst
27962796

2797+
.. include:: ../deprecations/pending-removal-in-3.20.rst
2798+
27972799
.. include:: ../deprecations/pending-removal-in-future.rst
27982800

27992801

Doc/whatsnew/3.15.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,42 @@ hashlib
631631

632632
(Contributed by Bénédikt Tran in :gh:`134978`.)
633633

634+
__version__
635+
-----------
636+
637+
* The ``__version__`` attribute has been deprecated in these standard library
638+
modules and will be removed in Python 3.20.
639+
Use :py:data:`sys.version_info` instead.
640+
641+
- :mod:`argparse`
642+
- :mod:`csv`
643+
- :mod:`!ctypes.macholib`
644+
- :mod:`ipaddress`
645+
- :mod:`json`
646+
- :mod:`logging` (``__date__`` also deprecated)
647+
- :mod:`optparse`
648+
- :mod:`pickle`
649+
- :mod:`platform`
650+
- :mod:`re`
651+
- :mod:`socketserver`
652+
- :mod:`tabnanny`
653+
- :mod:`tkinter.font`
654+
- :mod:`tkinter.ttk`
655+
656+
(Contributed by Hugo van Kemenade in :gh:`76007`.)
634657

635658
.. Add deprecations above alphabetically, not here at the end.
636659
660+
.. include:: ../deprecations/pending-removal-in-3.16.rst
661+
662+
.. include:: ../deprecations/pending-removal-in-3.17.rst
663+
664+
.. include:: ../deprecations/pending-removal-in-3.19.rst
665+
666+
.. include:: ../deprecations/pending-removal-in-3.20.rst
667+
668+
.. include:: ../deprecations/pending-removal-in-future.rst
669+
637670
Removed
638671
=======
639672

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, 20))
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, 20))
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, 20))
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, 20))
2426+
return "1.0" # Do not change
2427+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)