Skip to content

Python's help utility crashes when collections.abc module is asked. #123339

Closed

Description

@taaaf11

Bug 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

Activity

  1. taaaf11 commented on Aug 26, 2024

    @taaaf11
    Author
  2. deleted a comment from on Aug 26, 2024
  3. Eclips4 commented on Aug 26, 2024

    @Eclips4
  4. taaaf11 commented on Aug 26, 2024

    @taaaf11
    Author
  5. picnixz commented on Aug 26, 2024

    @picnixz
    Member

    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).

  6. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Aug 26, 2024
  7. serhiy-storchaka commented on Aug 28, 2024

    @serhiy-storchaka
    Member

    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.

  8. picnixz commented on Aug 28, 2024

    @picnixz
    Member

    The issue is likely due to the fact that _collections_abc has it's name set to collections.abc (#123347 (comment))

  9. serhiy-storchaka commented on Sep 2, 2024

    @serhiy-storchaka
    Member

    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__.

  10. picnixz commented on Sep 2, 2024

    @picnixz
    Member

    I'll work on something now. I'm done with what I wanted to do today.

  11. picnixz commented on Sep 2, 2024

    @picnixz
    Member

    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.

  12. self-assigned this
    on Sep 2, 2024
  13. added a commit that references this issue on Sep 2, 2024
  14. serhiy-storchaka commented on Sep 2, 2024

    @serhiy-storchaka
    Member

    I already had a ready solution, just was not able to create a PR due to a power outage.

  15. moved this from Todo to In Progress in Inspect issues 🔍on Sep 2, 2024
  16. added a commit that references this issue on Sep 2, 2024
  17. removed their assignment
    on Sep 3, 2024
  18. added 2 commits that reference this issue on Sep 28, 2024
  19. added a commit that references this issue on Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions