You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python's help utility crashes when collections.abc module is asked. #123339
and I assume that firstlineno is too large for lines. There is a check if lnum >= len(lines) but only for non-class objects. I can prepare a patch (and it seems it fixes the issue).
Why these classes have the wrong value at first place? I suspect there is a different issue behind this, and clipping the line number can just sweep it under cover.
This is a severe issue. Modules collections.abc and decimal are affected completely, because their content is defined in other files. But several other classes in other modules, like abc.ABCMeta or tomllib.TOMLDecodeError are affected too.
For collections.abc and decimal the solution can be replacing these modules completely in sys.modules This allows to get sources of classes in these modules (previously this did not work). For other classes with changed __module__ the only solution is to delete __firstlineno__. Since this issue can affect not only the stdlib classes, it is better to do this on the low level: setting __module__ will delete __firstlineno__.
Ok, I've tried to simply change the type.__module__ setter but it appears it's not sufficient enough. I have the idea but I don't have the time today. So I'll do it tomorrow.
Activity
taaaf11 commentedon Aug 26, 2024
Eclips4 commentedon Aug 26, 2024
taaaf11 commentedon Aug 26, 2024
picnixz commentedon Aug 26, 2024
It appears that
lines, lnum = findsource(object)returns objects withlen(lines) < lnum. It appears that:and I assume that firstlineno is too large for lines. There is a check
if lnum >= len(lines)but only for non-class objects. I can prepare a patch (and it seems it fixes the issue).serhiy-storchaka commentedon Aug 28, 2024
Why these classes have the wrong value at first place? I suspect there is a different issue behind this, and clipping the line number can just sweep it under cover.
picnixz commentedon Aug 28, 2024
The issue is likely due to the fact that
_collections_abchas it's name set tocollections.abc(#123347 (comment))serhiy-storchaka commentedon Sep 2, 2024
This is a severe issue. Modules
collections.abcanddecimalare affected completely, because their content is defined in other files. But several other classes in other modules, likeabc.ABCMetaortomllib.TOMLDecodeErrorare affected too.For
collections.abcanddecimalthe solution can be replacing these modules completely insys.modulesThis allows to get sources of classes in these modules (previously this did not work). For other classes with changed__module__the only solution is to delete__firstlineno__. Since this issue can affect not only the stdlib classes, it is better to do this on the low level: setting__module__will delete__firstlineno__.picnixz commentedon Sep 2, 2024
I'll work on something now. I'm done with what I wanted to do today.
picnixz commentedon Sep 2, 2024
Ok, I've tried to simply change the
type.__module__setter but it appears it's not sufficient enough. I have the idea but I don't have the time today. So I'll do it tomorrow.pythongh-123339: Fix cases of inconsistency of __module__ and __first…
serhiy-storchaka commentedon Sep 2, 2024
I already had a ready solution, just was not able to create a PR due to a power outage.
pythongh-123339: Fix cases of inconsistency of __module__ and __first…
gh-123339: Fix cases of inconsistency of __module__ and __firstlineno…
[3.13] pythongh-123339: Fix cases of inconsistency of __module__ and …
[3.13] gh-123339: Fix cases of inconsistency of __module__ and __firs…