Rephrases the rules for the | operator to just say that situations that previously resulted in a UnionType static type should now result in a TypeExpr[X | Y] static type, rather than attempting to directly specify the existing complex (and undocumented?) rules for the | operator.
Removes the ability to assign a TypeExpr[X | Y] to a UnionType, which implies a backward compatibility break for the rare functions that use UnionType in their signature. Migration guidance is added to §“Backward Compatibility”.
Feedback is welcome.
After the above items are ironed out, I’ll move on to altering the name of the concept that PEP 747 introduces, which I expect will be a monster of a diff.
A new draft of the TypeForm (previously: TypeExpr) PEP is ready for review in this PR! This latest draft is brought to you by @erictraut , a new co-author for the PEP.
Major changes include:
Refining and clarifying the terminology and definitions
ex: TypeExpr → TypeForm (biggest rename)
Eliminating the detailed implicit evaluation rules for every kind of type expression.
Instead, anything that conforms to the typing spec’s definition of a “type expression” should be accepted when assigned to a variable or passed to a function parameter that is explicitly annotated as TypeForm.
Please leave general comments in this thread and more-specific comments in the PR itself.
The next version of pyright (1.1.381), likely released Tues 9/17, will include provisional support for TypeForm as described in this draft. The new functionality is off by default, but it can be enabled by setting “enableExperimentalFeatures” to true in the pyright configuration.
I’m planning to work on mypy support for TypeForm over the next two weeks.