GeezerVison is showing github.com — Python's help utility crashes when `collections.abc` module is asked. · Issue #123339 · python/cpython
Python's help utility crashes when collections.abc module is asked. #123339DescriptionBug report
Bug description:
I am running Python 3.13.0-b2 on Debian 12 i386. When collections.abc is entered into python interactive help utility, the interpreter crashes.
>>> help
>>> collections.abc
(Python interpreter crashes)
The traceback is indented. So I am attaching video.
recording.mp4
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
Activitytaaaf11 commented on Aug 26, 2024 Author show commentMore actions Eclips4 commented on Aug 26, 2024 taaaf11 commented on Aug 26, 2024 Author show commentMore actions picnixz commented on Aug 26, 2024 It appears that lines, lnum = findsource(object) returns objects with len(lines) < lnum. It appears that:
if isclass(object):
try:
firstlineno = vars(object)['__firstlineno__']
except (TypeError, KeyError):
raise OSError('source code not available')
return lines, firstlineno - 1
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 commented on 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 commented on Aug 28, 2024 The issue is likely due to the fact that _collections_abc has it's name set to collections.abc (#123347 (comment)) serhiy-storchaka commented on Sep 2, 2024 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__. picnixz commented on Sep 2, 2024 I'll work on something now. I'm done with what I wanted to do today. picnixz commented on 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. serhiy-storchaka commented on Sep 2, 2024 I already had a ready solution, just was not able to create a PR due to a power outage. added 2 commits that reference this issue on Sep 28, 2024gh-123339: Fix cases of inconsistency of __module__ and __firstlineno…
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|