-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes #123613
gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes #123613
Conversation
Serhiy, it's seems that you forgot to commit the actual fix(and tests) and accidentally added two |
…lineno__ in classes * Setting the __module__ attribute for a class now removes the __firstlineno__ item from the type's dict. * The _collections_abc and _pydecimal modules now completely replace the collections.abc and decimal modules after importing the latters. This allows to get the source of classes and functions defined in these modules. * inspect.findsource() now checks whether the first line number for a class is out of bound.
fa4c94a
to
f2a8b90
Compare
Thanks for noticing this @Eclips4! I somewhere accidentally used Two NEWS entries are intentional, as they belong to different sections (Core and Library). |
Doc/reference/datamodel.rst
Outdated
@@ -1008,6 +1008,7 @@ Special attributes: | |||
|
|||
:attr:`__firstlineno__` | |||
The line number of the first line of the class definition, including decorators. | |||
Setting :attr:`__module__` removes :attr:`__firstlineno__`. |
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.
Setting :attr:`__module__` removes :attr:`__firstlineno__`. | |
Setting :attr:`!__module__` removes :attr:`!__firstlineno__`. |
Note that the link to __module__
does not exist (we don't have a global .. attribute:: __module__
). We can address this issue in a follow-up PR, but for now, let's just suppress the link.
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.
Well, the link to __firstlineno__
should be suppressed, but the link to __module__
may work in future.
Doc/reference/datamodel.rst
Outdated
@@ -1008,6 +1008,7 @@ Special attributes: | |||
|
|||
:attr:`__firstlineno__` | |||
The line number of the first line of the class definition, including decorators. | |||
Setting :attr:`__module__` removes :attr:`__firstlineno__`. |
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.
Well, the link to __firstlineno__
should be suppressed, but the link to __module__
may work in future.
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
…__firstlineno__ in classes (pythonGH-123613) * Setting the __module__ attribute for a class now removes the __firstlineno__ item from the type's dict. * The _collections_abc and _pydecimal modules now completely replace the collections.abc and decimal modules after importing them. This allows to get the source of classes and functions defined in these modules. * inspect.findsource() now checks whether the first line number for a class is out of bound. (cherry picked from commit 69a4063) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-124735 is a backport of this pull request to the 3.13 branch. |
…tlineno__ in classes (GH-123613) (#124735) * Setting the __module__ attribute for a class now removes the __firstlineno__ item from the type's dict. * The _collections_abc and _pydecimal modules now completely replace the collections.abc and decimal modules after importing them. This allows to get the source of classes and functions defined in these modules. * inspect.findsource() now checks whether the first line number for a class is out of bound. (cherry picked from commit 69a4063)
__module__
attribute for a class now removes the__firstlineno__
item from the type's dict.collections.abc
module is asked. #123339