File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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
@@ -1606,5 +1608,27 @@ def stress_lazy_imports(idx):
16061608 self .assertIn ("OK" , result .stdout )
16071609
16081610
1611+ class LazyImportDisTests (unittest .TestCase ):
1612+ def test_lazy_import_dis (self ):
1613+ """dis should properly show lazy import"""
1614+ code = compile ("lazy import foo" , "exec" , "exec" )
1615+ f = io .StringIO ()
1616+ dis .dis (code , file = f )
1617+ self .assertIn ("foo + lazy" , f .getvalue ())
1618+
1619+ def test_normal_import_dis (self ):
1620+ """non lazy imports should just show the name"""
1621+ code = compile ("import foo" , "exec" , "exec" )
1622+ f = io .StringIO ()
1623+ dis .dis (code , file = f )
1624+ for line in f .getvalue ().split ('\n ' ):
1625+ if "IMPORT_NAME" in line :
1626+ self .assertIn ("(foo)" , line )
1627+ break
1628+ else :
1629+ self .assertFail ("IMPORT_NAME not found" )
1630+
1631+
1632+
16091633if __name__ == '__main__' :
16101634 unittest .main ()
You can’t perform that action at this time.
0 commit comments