mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
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.
This commit is contained in:
parent
716ec4bfcf
commit
153b3f7530
17 changed files with 61 additions and 89 deletions
|
@ -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')]
|
||||
>>>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue