Skip to content

Commit 2bdf4b9

Browse files
committed
Deprecate version attribute in xml.sax.expatreader
1 parent c88d33f commit 2bdf4b9

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Pending removal in Python 3.20
22
------------------------------
33

4-
* The ``__version__`` and ``VERSION`` attributes have been deprecated in these
5-
standard library modules and will be removed in Python 3.20.
6-
Use :py:data:`sys.version_info` instead.
4+
* The ``__version__``, ``version`` and ``VERSION`` attributes have been
5+
deprecated in these standard library modules and will be removed in
6+
Python 3.20. Use :py:data:`sys.version_info` instead.
77

88
- :mod:`argparse`
99
- :mod:`csv`
@@ -24,6 +24,7 @@ Pending removal in Python 3.20
2424
- :mod:`tkinter.font`
2525
- :mod:`tkinter.ttk`
2626
- :mod:`xml.etree.ElementTree`
27+
- :mod:`xml.sax.expatreader`
2728
- :mod:`wsgiref.simple_server`
2829
- :mod:`zlib`
2930

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,9 @@ New deprecations
10181018

10191019
* ``__version__``
10201020

1021-
* The ``__version__`` and ``VERSION`` attributes have been deprecated in these
1022-
standard library modules and will be removed in Python 3.20.
1023-
Use :py:data:`sys.version_info` instead.
1021+
* The ``__version__``, ``version`` and ``VERSION`` attributes have been
1022+
deprecated in these standard library modules and will be removed in
1023+
Python 3.20. Use :py:data:`sys.version_info` instead.
10241024

10251025
- :mod:`argparse`
10261026
- :mod:`csv`
@@ -1041,6 +1041,7 @@ New deprecations
10411041
- :mod:`tkinter.font`
10421042
- :mod:`tkinter.ttk`
10431043
- :mod:`xml.etree.ElementTree`
1044+
- :mod:`xml.sax.expatreader`
10441045
- :mod:`wsgiref.simple_server`
10451046
- :mod:`zlib`
10461047

Lib/test/test_sax.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,5 +1573,15 @@ def test_all(self):
15731573
check__all__(self, sax, extra=extra)
15741574

15751575

1576+
class TestModule(unittest.TestCase):
1577+
def test_deprecated_version(self):
1578+
with self.assertWarnsRegex(
1579+
DeprecationWarning,
1580+
"'version' is deprecated and slated for removal in Python 3.20",
1581+
) as cm:
1582+
getattr(sax.expatreader, "version")
1583+
self.assertEqual(cm.filename, __file__)
1584+
1585+
15761586
if __name__ == "__main__":
15771587
unittest.main()

Lib/xml/sax/expatreader.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
pyexpat.__version__ == '2.22'.
44
"""
55

6-
version = "0.20"
7-
86
from xml.sax._exceptions import *
97
from xml.sax.handler import feature_validation, feature_namespaces
108
from xml.sax.handler import feature_namespace_prefixes
@@ -446,9 +444,19 @@ def create_parser(*args, **kwargs):
446444

447445
# ---
448446

447+
def __getattr__(name):
448+
if name == "version":
449+
from warnings import _deprecated
450+
451+
_deprecated("version", remove=(3, 20))
452+
return "0.20" # Do not change
453+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
454+
455+
# ---
456+
449457
if __name__ == "__main__":
450458
import xml.sax.saxutils
451459
p = create_parser()
452460
p.setContentHandler(xml.sax.saxutils.XMLGenerator())
453461
p.setErrorHandler(xml.sax.ErrorHandler())
454-
p.parse("http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml")
462+
p.parse("https://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml")

0 commit comments

Comments
 (0)