https://github.com/python/cpython/commit/2dd5315a76edf01a56293bc01d1e828f8144d6d5 commit: 2dd5315a76edf01a56293bc01d1e828f8144d6d5 branch: main author: Jelle van der Waa <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-10-19T19:57:20+01:00 summary:
gh-159675: Tidy and lazify imports in `xml.sax.saxutils` (#159676) Co-authored-by: Stan Ulbrych <[email protected]> files: M Lib/test/test_sax.py M Lib/xml/sax/saxutils.py diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 46b29650d9383b5..14e5306398107a7 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -24,8 +24,8 @@ import sys from urllib.error import URLError import urllib.request -from test.support import os_helper -from test.support import findfile, check__all__ +from test.support import (check__all__, cpython_only, findfile, + import_helper, os_helper) from test.support.os_helper import FakePath, TESTFN @@ -1600,6 +1600,12 @@ def test_deprecated__version__and__date__(self): getattr(module, "version") self.assertEqual(cm.filename, __file__) + @cpython_only + def test_lazy_import(self): + import_helper.ensure_lazy_imports( + "xml.sax.saxutils", {"urllib.parse", "urllib.request"} + ) + if __name__ == "__main__": unittest.main() diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py index 920283c3f3496f0..8225989d60ecec8 100644 --- a/Lib/xml/sax/saxutils.py +++ b/Lib/xml/sax/saxutils.py @@ -3,9 +3,12 @@ convenience of application and driver writers. """ -import os, urllib.parse, urllib.request -import io import codecs +import io +import os +import sys +lazy import urllib.parse +lazy import urllib.request from . import handler from . import xmlreader @@ -70,7 +73,6 @@ def quoteattr(data, entities={}): def _gettextwriter(out, encoding): if out is None: - import sys return sys.stdout if isinstance(out, io.TextIOBase): _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
