GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot call `issubclass()` against `typing.Protocol` on Python 3.12 · Issue #105237 · python/cpython

Cannot call issubclass() against typing.Protocol on Python 3.12 #105237

New issue
Copy link
New issue
Copy link
Closed
Closed
Cannot call issubclass() against typing.Protocol on Python 3.12#105237
Copy link
Assignees
AlexWaygood
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@AlexWaygood
AlexWaygood
opened on Jun 2, 2023
Issue body actions

Bug report

On Python 3.11, you can do this:

>>> import typing
>>> issubclass(object, typing.Protocol)
False

But on Python 3.12 (following the backport of c05c31d), this raises:

>>> import typing
>>> issubclass(object, typing.Protocol)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1797, in __subclasscheck__
    raise TypeError(
TypeError: Instance and class checks can only be used with @runtime_checkable protocols

The new behaviour doesn't make sense. That TypeError should only be triggered if a user is calling issubclass() against a subclass of typing.Protocol. typing.Protocol itself should be exempted.

Linked PRs

  • gh-105237: Allow calling issubclass(X, typing.Protocol) again #105239
  • [3.12] gh-105237: Allow calling issubclass(X, typing.Protocol) again (GH-105239) #105316
Reacted by sunmy2019

Activity

  1. AlexWaygood
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-typing
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    on Jun 2, 2023
  2. AlexWaygood
    self-assigned this
    on Jun 2, 2023
  3. JelleZijlstra
    added a commit that references this issue on Jun 5, 2023

    gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (#105239

    cdfb201
  4. miss-islington
    added a commit that references this issue on Jun 5, 2023

    pythongh-105237: Allow calling `issubclass(X, typing.Protocol)` again (…

    f45b5d7
  5. AlexWaygood
    added a commit that references this issue on Jun 5, 2023

    [3.12] gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (

    5175026
  6. AlexWaygood commented on Jun 5, 2023

    @AlexWaygood
    AlexWaygood
    on Jun 5, 2023
    MemberAuthor
    More actions

    While working on fixing the bug, we discovered another bug, where issubclass(object, Protocol) can sometimes evaluate to True. Unlike the original bug, this one reproduces all the way back to Python 3.8. It's now fixed on main and 3.12, but it might be good to see if we can fix it on 3.11 as well.

  7. AlexWaygood commented on Jun 5, 2023

    @AlexWaygood
    AlexWaygood
    on Jun 5, 2023
    MemberAuthor
    More actions

    While working on fixing the bug, we discovered another bug, where issubclass(object, Protocol) can sometimes evaluate to True. Unlike the original bug, this one reproduces all the way back to Python 3.8. It's now fixed on main and 3.12, but it might be good to see if we can fix it on 3.11 as well.

    Well, but on the other hand, I'm hesitant to touch 3.11 here, given that it's an edge-case bug, and it's hard to do a proper fix that's not somewhat invasive. So, I'll close this for now. (But if somebody else disagrees and wants to have a go at fixing it on 3.11, happy to reopen.)

  8. AlexWaygood
    closed this as completedon Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @AlexWaygood
    AlexWaygood

Labels

3.12only security fixesonly security fixes3.13only security fixesonly security fixestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.