Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-118465: Add __firstlineno__ attribute to class#118475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
It is set by compiler with the line number of the first line ofthe class definition.
Uh oh!
There was an error while loading.Please reload this page.
@@ -280,6 +280,11 @@ Other Language Changes | |||
class scopes are not inlined into their parent scope. (Contributed by | |||
Jelle Zijlstra in :gh:`109118` and :gh:`118160`.) | |||
* 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.
Choose a reason for 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.
There was a problem hiding this comment.
Choose a reason for 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 forco_firstlineno
etc.
Co-authored-by: Mark Shannon <mark@hotpy.org>
@@ -280,6 +280,11 @@ Other Language Changes | |||
class scopes are not inlined into their parent scope. (Contributed by | |||
Jelle Zijlstra in :gh:`109118` and :gh:`118160`.) | |||
* 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.
Choose a reason for 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 forco_firstlineno
etc.
Uh oh!
There was an error while loading.Please reload this page.
It is possible to construct classes without deff():__firstlineno__=1classX:nonlocal__firstlineno__returnXprint(f().__firstlineno__)# AttributeError Or: classY: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
|
Good point. I thought that it is the same as for We can try to set I think that for backward compatibility |
Uh oh!
There was an error while loading.Please reload this page.
It is set by compiler with the line number of the first line of the class definition.
📚 Documentation preview 📚:https://cpython-previews--118475.org.readthedocs.build/