Skip to content

UP035 recommends change that changes runtime behavior for is_typeddict #15780

Closed
@SebbyLaw

Description

Description

is_typeddict from the typing module does not correctly identify TypedDict from the typing_extensions module:

from typing_extensions import is_typeddict as is_typeddict_te, TypedDict as TypedDict_te
from typing import is_typeddict, TypedDict

class Ext(TypedDict_te):
    a: int

class Reg(TypedDict):
    a: int

print("is_typeddict(Ext):", is_typeddict(Ext))  # False
print("is_typeddict(Reg):", is_typeddict(Reg))  # True
print("is_typeddict_te(Ext):", is_typeddict_te(Ext))  # True
print("is_typeddict_te(Reg):", is_typeddict_te(Reg))  # True

In the description of UP035:

Note that, in some cases, it may be preferable to continue importing members from typing_extensions even after they're added to the Python standard library, as typing_extensions can backport bugfixes and optimizations from later Python versions. This rule thus avoids flagging imports from typing_extensions in such cases.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions