Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Doc/deprecations/pending-removal-in-3.20.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Pending removal in Python 3.20
------------------------------

* The ``__version__`` attribute has been deprecated in these standard library
modules and will be removed in Python 3.20.
Use :py:data:`sys.version_info` instead.
* The ``__version__``, ``version`` and ``VERSION`` attributes have been
deprecated in these standard library modules and will be removed in
Python 3.20. Use :py:data:`sys.version_info` instead.

- :mod:`argparse`
- :mod:`csv`
Expand All @@ -24,6 +24,9 @@ Pending removal in Python 3.20
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`wsgiref.simple_server`
- :mod:`xml.etree.ElementTree`
- :mod:`!xml.sax.expatreader`
- :mod:`xml.sax.handler`
- :mod:`zlib`

(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
9 changes: 6 additions & 3 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,9 @@ New deprecations

* ``__version__``

* The ``__version__`` attribute has been deprecated in these standard library
modules and will be removed in Python 3.20.
Use :py:data:`sys.version_info` instead.
* The ``__version__``, ``version`` and ``VERSION`` attributes have been
deprecated in these standard library modules and will be removed in
Python 3.20. Use :py:data:`sys.version_info` instead.

- :mod:`argparse`
- :mod:`csv`
Expand All @@ -1041,6 +1041,9 @@ New deprecations
- :mod:`tkinter.font`
- :mod:`tkinter.ttk`
- :mod:`wsgiref.simple_server`
- :mod:`xml.etree.ElementTree`
- :mod:`!xml.sax.expatreader`
- :mod:`xml.sax.handler`
- :mod:`zlib`

(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_sax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,5 +1573,17 @@ def test_all(self):
check__all__(self, sax, extra=extra)


class TestModule(unittest.TestCase):
def test_deprecated__version__and__date__(self):
for module in (sax.expatreader, sax.handler):
with self.subTest(module=module):
with self.assertWarnsRegex(
DeprecationWarning,
"'version' is deprecated and slated for removal in Python 3.20",
) as cm:
getattr(module, "version")
self.assertEqual(cm.filename, __file__)


if __name__ == "__main__":
unittest.main()
13 changes: 13 additions & 0 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4705,6 +4705,19 @@ def get_option(config, option_name, default=None):

# --------------------------------------------------------------------


class TestModule(unittest.TestCase):
def test_deprecated_version(self):
with self.assertWarnsRegex(
DeprecationWarning,
"'VERSION' is deprecated and slated for removal in Python 3.20",
) as cm:
getattr(ET, "VERSION")
self.assertEqual(cm.filename, __file__)


# --------------------------------------------------------------------

def setUpModule(module=None):
# When invoked without a module, runs the Python ET tests by loading pyET.
# Otherwise, uses the given module as the ET.
Expand Down
14 changes: 11 additions & 3 deletions Lib/xml/etree/ElementTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,12 @@
"SubElement",
"tostring", "tostringlist",
"TreeBuilder",
"VERSION",
"XML", "XMLID",
"XMLParser", "XMLPullParser",
"register_namespace",
"canonicalize", "C14NWriterTarget",
]

VERSION = "1.3.0"

import sys
import re
import warnings
Expand Down Expand Up @@ -2104,3 +2101,14 @@ def _escape_attrib_c14n(text):
pass
else:
_set_factories(Comment, ProcessingInstruction)


# --------------------------------------------------------------------

def __getattr__(name):
if name == "VERSION":
from warnings import _deprecated

_deprecated("VERSION", remove=(3, 20))
return "1.3.0" # Do not change
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
12 changes: 10 additions & 2 deletions Lib/xml/sax/expatreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
pyexpat.__version__ == '2.22'.
"""

version = "0.20"

from xml.sax._exceptions import *
from xml.sax.handler import feature_validation, feature_namespaces
from xml.sax.handler import feature_namespace_prefixes
Expand Down Expand Up @@ -446,6 +444,16 @@ def create_parser(*args, **kwargs):

# ---

def __getattr__(name):
if name == "version":
from warnings import _deprecated

_deprecated("version", remove=(3, 20))
return "0.20" # Do not change
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

# ---

if __name__ == "__main__":
import xml.sax.saxutils
p = create_parser()
Expand Down
11 changes: 9 additions & 2 deletions Lib/xml/sax/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
$Id$
"""

version = '2.0beta'

#============================================================================
#
# HANDLER INTERFACES
Expand Down Expand Up @@ -385,3 +383,12 @@ def startCDATA(self):

def endCDATA(self):
"""Reports the end of a CDATA marked section."""


def __getattr__(name):
if name == "version":
from warnings import _deprecated

_deprecated("version", remove=(3, 20))
return "2.0beta" # Do not change
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree` and ``version`` from
:mod:`!xml.sax.expatreader` and :mod:`xml.sax.handler`. Patch by Hugo van
Kemenade.
Loading