diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-05-06 09:02:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-06 09:02:37 (GMT) |
commit | 153b3f75306b5d26e29ea157105d0fdc247ef853 (patch) | |
tree | f73ede56af175d27698ef56bec21073f98889bbc /Lib/test/test_metaclass.py | |
parent | 716ec4bfcf1a564db9936122c442baa99f9c4a8c (diff) | |
download | cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.zip cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.tar.gz cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.tar.bz2 |
gh-118465: Add __firstlineno__ attribute to class (GH-118475)
It is set by compiler with the line number of the first line of
the class definition.
Diffstat (limited to 'Lib/test/test_metaclass.py')
-rw-r--r-- | Lib/test/test_metaclass.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/test/test_metaclass.py b/Lib/test/test_metaclass.py index 70f9c5d..b37b7de 100644 --- a/Lib/test/test_metaclass.py +++ b/Lib/test/test_metaclass.py @@ -164,6 +164,7 @@ Use a __prepare__ method that returns an instrumented dict. ... d['__module__'] = 'test.test_metaclass' d['__qualname__'] = 'C' + d['__firstlineno__'] = 1 d['foo'] = 4 d['foo'] = 42 d['bar'] = 123 @@ -183,12 +184,12 @@ Use a metaclass that doesn't derive from type. ... b = 24 ... meta: C () - ns: [('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('__static_attributes__', ()), ('a', 42), ('b', 24)] + ns: [('__firstlineno__', 1), ('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('__static_attributes__', ()), ('a', 42), ('b', 24)] kw: [] >>> type(C) is dict True >>> print(sorted(C.items())) - [('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('__static_attributes__', ()), ('a', 42), ('b', 24)] + [('__firstlineno__', 1), ('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('__static_attributes__', ()), ('a', 42), ('b', 24)] >>> And again, with a __prepare__ attribute. @@ -206,12 +207,13 @@ And again, with a __prepare__ attribute. prepare: C () [('other', 'booh')] d['__module__'] = 'test.test_metaclass' d['__qualname__'] = 'C' + d['__firstlineno__'] = 1 d['a'] = 1 d['a'] = 2 d['b'] = 3 d['__static_attributes__'] = () meta: C () - ns: [('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('__static_attributes__', ()), ('a', 2), ('b', 3)] + ns: [('__firstlineno__', 1), ('__module__', 'test.test_metaclass'), ('__qualname__', 'C'), ('__static_attributes__', ()), ('a', 2), ('b', 3)] kw: [('other', 'booh')] >>> |