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
|
|
||
| :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.
| 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.
Well, the link to __firstlineno__ should be suppressed, but the link to __module__ may work in future.
Doc/reference/datamodel.rst
Outdated
|
|
||
| :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.
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.abcmodule is asked. #123339