GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-118465: Add __firstlineno__ attribute to class by serhiy-storchaka · Pull Request #118475 · python/cpython Conversation
|
|
|
||
| * Classes have a new :attr:`!__firstlineno__` attribute, | ||
| populated by the compiler, with the line number of the first line | ||
| of the class definition. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If the class has decorators then I think this is the first line of the first decorator. Need a test for this case, and probably to mention in the doc.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There are existing tests, and they are passed.
I'll add explicit mentioning of this fact, but AFAIK it was not specified for co_firstlineno etc.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Mark Shannon <[email protected]>
|
|
||
| * Classes have a new :attr:`!__firstlineno__` attribute, | ||
| populated by the compiler, with the line number of the first line | ||
| of the class definition. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There are existing tests, and they are passed.
I'll add explicit mentioning of this fact, but AFAIK it was not specified for co_firstlineno etc.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
It is possible to construct classes without def f(): __firstlineno__ = 1 class X: nonlocal __firstlineno__ return X print(f().__firstlineno__) # AttributeError Or: class Y: global __firstlineno__ print(Y.__firstlineno__) # AttributeError This is obviously an extreme edge case though. You could also do this by manipulating Is it worth it to make |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Good point. I thought that it is the same as for We can try to set I think that for backward compatibility |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.