bpo-39316: Make sure that attribute accesses and stores, including method calls, conform to PEP 626. (GH-24859)

This commit is contained in:
Mark Shannon 2021-03-14 18:01:30 +00:00 committed by GitHub
parent cd8dcbc851
commit d48848c83e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 6 deletions

View file

@ -837,6 +837,51 @@ if 1:
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