traits
traits copied to clipboard
Use | operator for Union traits
Following PEP 604 which allows constructs like int | float
as a replacement for Union[int, float]
should we allow Int | Float
as an (optional) replacement for Union(Int, Float)
?
The good:
- meaning is fairly clear
- alignment with Python typing
The bad:
- if you want metadata then you'd have to do something like
(Int | Float)(foo='bar')
which is not very clear compared toUnion(Int, Float, foo='bar')
The ugly:
-
Int | Float
orInt() | Float()
? It may have to be the latter, but presumably Python is going to grow some hook for|
for types with this change, the same way it did for getitem.
Note that PEP 593 allows you to annotate annotations with metadata.