Skip to content

Spec: Mandate support for typing-extensions #1532

Description

@JelleZijlstra

The typing spec should mandate that type checkers support the typing_extensions module by treating any name imported from it as equivalent to the same name in typing.

This is noncontroversial (I hope!), but it's still a substantive change to the spec, so it should go through the procedure in https://github.com/python/typing-council?tab=readme-ov-file#decisions. I'll likely do that in January.

Activity

  1. JelleZijlstra commented on May 23, 2024

    @JelleZijlstra
    MemberAuthor

    This was arguably addressed by the type expressions change (#1693), now at https://typing.readthedocs.io/en/latest/spec/annotations.html#type-and-annotation-expressions, which says "Most special forms must be imported from typing or typing_extensions". However, it's probably still useful to have a section mentioning typing-extensions more explicitly.

  2. davidhewitt commented on Sep 6, 2026

    @davidhewitt

    We have recently been debating in PyO3 what to do about typing constructs not available in our full range of supported Python versions for the type hints which we are now generating from Rust modules.

    Based on this proposal here, it seems like it would be fine to just import these from typing_extensions (e.g. disjoint_base), rather than having a conditional import based on sys.version_info.

    It would be helpful to have this formalised in the spec so that we can be certain what we're doing is compliant.

  3. davidhalter commented on Sep 6, 2026

    @davidhalter
    Collaborator

    While this is not in the spec and should probably be formalized, I think all type checkers have the understanding that typing_extensions should work exactly like typing. There are a lot of typing_extensions imports out in the wild so as a type checker you have to practically deal with typing_extensions anyway.

  4. davidhewitt commented on Sep 6, 2026

    @davidhewitt

    That was our empirical observation too.

  5. JelleZijlstra commented on Sep 6, 2026

    @JelleZijlstra
    MemberAuthor

    @davidhewitt if you do this in stub files it should be fine. If it's in runtime code you need a little more care, as you do have to declare the typing-extensions runtime dependency.

  6. jorenham commented on Sep 6, 2026

    @jorenham
    Collaborator

    If it's in runtime code you need a little more care, as you do have to declare the typing-extensions runtime dependency.

    You can also import it within if TYPE_CHECKING: to avoid the dependency

  7. davidhewitt commented on Sep 6, 2026

    @davidhewitt

    For now these are all .pyi files, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions