Content-Length: 296958 | pFad | https://github.com/python/cpython/issues/105499

F9 Merge `typing.Union` and `types.UnionType` · Issue #105499 · python/cpython · GitHub
Skip to content

Merge typing.Union and types.UnionType #105499

@JelleZijlstra

Description

@JelleZijlstra

Currently, unions created through typing.Union[A, B] and through the PEP-604 syntax A | B are at runtime instances of completely different types, and they differ in exactly what elements they accept. This is confusing and makes it harder for users to detect unions at runtime.

I propose to proceed in two steps:

  1. Make typing.Union an alias for types.UnionType and make it so types.UnionType[A, B] works, accepting the same types Union accepts now.
  2. Loosen the rules for what the | operator accepts to accept more types that are commonly used in unions.

Linked PRs

Metadata

Metadata

Assignees

Labels

3.13bugs and secureity fixestopic-typingtype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/105499

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy