Skip to content

typing._allow_reckless_class_checks doesn't work when _abc doesn't exist. #136047

Open

Description

@youknowone

Bug report

Bug description:

When typing._caller's sys._getframe fallback is triggered without _abc module, _typing._allow_reckless_class_checks fails to check _py_abc while running abc.ABCMeta.__instancecheck__.

Without _abc module, _typing._allow_reckless_class_checksfails to check _py_abc

Related code in typing.py:
https://github.com/python/cpython/blob/v3.14.0b3/Lib/typing.py#L1846-L1863

This is technically a bug of typing.py, but really hard to be triggered on CPython.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Solution suggestion

Patch typing._allow_reckless_class_checks to also check _py_abc

This is the most conservative approach. Compatible with all of previous scenarios and additionally fixing the bug.

Patch typing._caller to remove sys._getframe or raise warning when fallback

If the the typing requires to work with sys._getframemodulename, then let the users to know it has a caveat.

Linked PRs

Activity

  1. youknowone commented on Jun 27, 2025

    @youknowone
    ContributorAuthor

    Sorry, though the error is different, I couldn't confirm it leads actual behavior difference. I will open it again if it cause actual problem.

    Revised the content with the real cause

  2. changed the title [-]_py_abc.ABCMeta.__instancecheck__ is not compatible to abc.ABCMeta.__instancecheck__[/-] [+]typing._allow_reckless_class_checks doesn't work when sys._getframemodulename and _abc don't exist.[/+] on Jun 30, 2025
  3. added a commit that references this issue on Jun 30, 2025
  4. changed the title [-]typing._allow_reckless_class_checks doesn't work when sys._getframemodulename and _abc don't exist.[/-] [+]typing._allow_reckless_class_checks doesn't work when _abc doesn't exist.[/+] on Jun 30, 2025
  5. added a commit that references this issue on Jul 5, 2025
  6. added a commit that references this issue on Jul 11, 2025
  7. added a commit that references this issue on Jul 12, 2025
  8. added a commit that references this issue on Jul 13, 2025
  9. added a commit that references this issue on Aug 4, 2025
  10. added a commit that references this issue on Aug 19, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions