Skip to content

Commit 2dd5315

Browse files
gh-159675: Tidy and lazify imports in xml.sax.saxutils (#159676)
Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 02844c8 commit 2dd5315

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎Lib/test/test_sax.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import sys
2525
from urllib.error import URLError
2626
import urllib.request
27-
from test.support import os_helper
28-
from test.support import findfile, check__all__
27+
from test.support import (check__all__, cpython_only, findfile,
28+
import_helper, os_helper)
2929
from test.support.os_helper import FakePath, TESTFN
3030

3131

@@ -1600,6 +1600,12 @@ def test_deprecated__version__and__date__(self):
16001600
getattr(module, "version")
16011601
self.assertEqual(cm.filename, __file__)
16021602

1603+
@cpython_only
1604+
def test_lazy_import(self):
1605+
import_helper.ensure_lazy_imports(
1606+
"xml.sax.saxutils", {"urllib.parse", "urllib.request"}
1607+
)
1608+
16031609

16041610
if __name__ == "__main__":
16051611
unittest.main()

‎Lib/xml/sax/saxutils.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
convenience of application and driver writers.
44
"""
55

6-
import os, urllib.parse, urllib.request
7-
import io
86
import codecs
7+
import io
8+
import os
9+
import sys
10+
lazy import urllib.parse
11+
lazy import urllib.request
912
from . import handler
1013
from . import xmlreader
1114

@@ -70,7 +73,6 @@ def quoteattr(data, entities={}):
7073

7174
def _gettextwriter(out, encoding):
7275
if out is None:
73-
import sys
7476
return sys.stdout
7577

7678
if isinstance(out, io.TextIOBase):

0 commit comments

Comments
 (0)