Skip to content

Different results in Python 3.12.1 vs Python 3.12.2 #335

Closed

Description

@tfeldmann

Small reproducer:

from dataclasses import dataclass

from typing_extensions import Protocol, runtime_checkable


@runtime_checkable  # removing this decorator fixes the bug.
class HasConfig(Protocol):
    pass

@runtime_checkable
class Action(HasConfig, Protocol):
    pass

@dataclass
class Delete:
    pass

delete = Delete()
print(isinstance(delete, Action))

This prints False in 3.12.2, True in 3.12.1. Changing the import to from typing import Protocol, runtime_checkable also makes this bug disappear.

Activity

  1. AlexWaygood commented on Feb 15, 2024

    @AlexWaygood
    Member

    This is because Python 3.12.2 changed the implementation of @runtime_checkable so that it now adds an attribute to the class it decorates, and the latest release of typing_extensions just re-exports the typing module's version of the @runtime_checkable rather than defining its own version.

    We've actually already fixed this bug on the typing_extensions main branch (in 004b893), but the fix hasn't been released yet.

    @JelleZijlstra -- thoughts on possibly reconsidering #324 (comment)? I think it might be worth cutting a patch release for this :/ Sorry for the bother :(

  2. JelleZijlstra commented on Feb 16, 2024

    @JelleZijlstra
    Member

    I feel the changes are too big for a bugfix release. I merged the PEP 742 implementation and hopefully we can also get PEP 728 implemented in the next few days, then make a release on Sunday (#337).

  3. AlexWaygood commented on Feb 25, 2024

    @AlexWaygood
    Member

    typing_extensions 4.10.0 has now been released, which should hopefully fix the issue! Let us know if you're still having problems @tfeldmann

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions