File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 11"""Tests for PEP 810 lazy imports."""
22
3- import sys
3+ import io
4+ import dis
45import subprocess
6+ import sys
57import textwrap
68import threading
79import types
@@ -1607,5 +1609,27 @@ def stress_lazy_imports(idx):
16071609 self .assertIn ("OK" , result .stdout )
16081610
16091611
1612+ class LazyImportDisTests (unittest .TestCase ):
1613+ def test_lazy_import_dis (self ):
1614+ """dis should properly show lazy import"""
1615+ code = compile ("lazy import foo" , "exec" , "exec" )
1616+ f = io .StringIO ()
1617+ dis .dis (code , file = f )
1618+ self .assertIn ("foo + lazy" , f .getvalue ())
1619+
1620+ def test_normal_import_dis (self ):
1621+ """non lazy imports should just show the name"""
1622+ code = compile ("import foo" , "exec" , "exec" )
1623+ f = io .StringIO ()
1624+ dis .dis (code , file = f )
1625+ for line in f .getvalue ().split ('\n ' ):
1626+ if "IMPORT_NAME" in line :
1627+ self .assertIn ("(foo)" , line )
1628+ break
1629+ else :
1630+ self .assertFail ("IMPORT_NAME not found" )
1631+
1632+
1633+
16101634if __name__ == '__main__' :
16111635 unittest .main ()
You can’t perform that action at this time.
0 commit comments