bpo-39316: Make sure that attribute accesses and stores, including method calls, conform to PEP 626. (GH-24859)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 1f12524..aa08c97 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -837,6 +837,51 @@ def no_code2():
self.assertEqual(end, len(code.co_code))
self.assertEqual(line, code.co_firstlineno)
+ def test_lineno_attribute(self):
+ def load_attr():
+ return (
+ o.
+ a
+ )
+ load_attr_lines = [ 2, 3, 1 ]
+
+ def load_method():
+ return (
+ o.
+ m(
+ 0
+ )
+ )
+ load_method_lines = [ 2, 3, 4, 3, 1 ]
+
+ def store_attr():
+ (
+ o.
+ a
+ ) = (
+ v
+ )
+ store_attr_lines = [ 5, 2, 3 ]
+
+ def aug_store_attr():
+ (
+ o.
+ a
+ ) += (
+ v
+ )
+ aug_store_attr_lines = [ 2, 3, 5, 1, 3 ]
+
+ funcs = [ load_attr, load_method, store_attr, aug_store_attr]
+ func_lines = [ load_attr_lines, load_method_lines,
+ store_attr_lines, aug_store_attr_lines]
+
+ for func, lines in zip(funcs, func_lines, strict=True):
+ with self.subTest(func=func):
+ code_lines = [ line-func.__code__.co_firstlineno
+ for (_, _, line) in func.__code__.co_lines() ]
+ self.assertEqual(lines, code_lines)
+
def test_big_dict_literal(self):
# The compiler has a flushing point in "compiler_dict" that calls compiles