Problem
PEP 604 allows the pipe symbol (|) to annotate unions of types. In particular:
X | Y $\equiv$ Union[X,Y]
and
X | None $\equiv$ Optional[X]
However, type forwarding does not work with this new capability. I.e. "Xtype" | Y doesn't work (though "Xtype | Y" does actually work).
Currently our repo is inconsistent when it comes to union types.
Solution
We should settle on a best practice for such annotations, change all usages to adhere to the best practice, and add it to our style guide.
I propose that we disallow | because of its incompatibility with forwarded types. But I'm open to discussion and don't have a strong opinion, except that we should have some convention.
Dependencies
None
Urgency
Very low
Problem
PEP 604 allows the pipe symbol (
|) to annotate unions of types. In particular:X | YUnion[X,Y]and
X | NoneOptional[X]However, type forwarding does not work with this new capability. I.e.
"Xtype" | Ydoesn't work (though"Xtype | Y"does actually work).Currently our repo is inconsistent when it comes to union types.
Solution
We should settle on a best practice for such annotations, change all usages to adhere to the best practice, and add it to our style guide.
I propose that we disallow
|because of its incompatibility with forwarded types. But I'm open to discussion and don't have a strong opinion, except that we should have some convention.Dependencies
None
Urgency
Very low