summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhan@python.org>2021-06-30 22:53:36 (GMT)
committerGitHub <noreply@github.com>2021-06-30 22:53:36 (GMT)
commit1b28187a0e3e914ee48de8032cbba0a965dd5563 (patch)
treeebdccc08b86369b90e61eb1066a8af68694589c0 /Lib/test
parent66c53b48e1f5c841d9f48e51ce7bf1a74b75b629 (diff)
downloadcpython-1b28187a0e3e914ee48de8032cbba0a965dd5563.zip
cpython-1b28187a0e3e914ee48de8032cbba0a965dd5563.tar.gz
cpython-1b28187a0e3e914ee48de8032cbba0a965dd5563.tar.bz2
bpo-44313: generate LOAD_ATTR/CALL_FUNCTION for top-level imported objects (GH-26677)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_compile.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 6dc1c38..7de607c 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -6,6 +6,7 @@ import sys
import _ast
import tempfile
import types
+import textwrap
from test import support
from test.support import script_helper
from test.support.os_helper import FakePath
@@ -791,6 +792,41 @@ if 1:
self.assertIn('LOAD_', opcodes[0].opname)
self.assertEqual('RETURN_VALUE', opcodes[1].opname)
+ def test_imported_load_method(self):
+ sources = [
+ """\
+ import os
+ def foo():
+ return os.uname()
+ """,
+ """\
+ import os as operating_system
+ def foo():
+ return operating_system.uname()
+ """,
+ """\
+ from os import path
+ def foo(x):
+ return path.join(x)
+ """,
+ """\
+ from os import path as os_path
+ def foo(x):
+ return os_path.join(x)
+ """
+ ]
+ for source in sources:
+ namespace = {}
+ exec(textwrap.dedent(source), namespace)
+ func = namespace['foo']
+ with self.subTest(func=func.__name__):
+ opcodes = list(dis.get_instructions(func))
+ instructions = [opcode.opname for opcode in opcodes]
+ self.assertNotIn('LOAD_METHOD', instructions)
+ self.assertNotIn('CALL_METHOD', instructions)
+ self.assertIn('LOAD_ATTR', instructions)
+ self.assertIn('CALL_FUNCTION', instructions)
+
def test_lineno_procedure_call(self):
def call():
(