Scala 3 propose a new syntax for Union type. See here. I propose to add a similar syntax in Python.
Now, it's possible to write:
in place of
The discussion on python-new@python.org here have emerged the idea of extending also issubclass() and isinstance().
I think these syntaxes are more clear, and can help with the adoption of typing.
I test and implement these ideas in a two fork : One for CPython and one for MyPy. See the branches add_OR_to_types (for Union syntax), add_INVERT_to_types (for Union and Optional syntax) or updage_isinstance (for new isinstance() and issubclass()).
How I implement that ? I add the operators __or__ and __revert__ to PyType_Type. The C code is similar of :
with some check before return Union.
Actually, the accepted BNF syntax for typing is :
I propose to extend the BNF syntax to :
Your remarks are welcome.