You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that implementing generic union types (X | Y and Union[X, Y]) are difficult to implement and are rejected. We can try to implement reduced version containing None since it is often used instead of typing.Optional[]. We can transform it as follows:
X | None = None | X -> typing.Optional[X]
X | Y | None = X | None | Y = None | X | Y -> typing.Optional[object]
X | Y | None = X | None | Y = None | X | Y -> typing.Optional[object]
typing.Union[X, Y, None] = typing.Union[X, None, Y] = typing.Union[None, X, Y] -> typing.Optional[object]
These two aren't hugely worthwhile in Cython (because if you type something as object we never generate code that assumes it isn't None). They're harmless, but covered by the current behaviour of "annotation that Cython doesn't understand -> object"
X | None = None | X -> typing.Optional[X]
typing.Union[X, None] = typing.Union[None, X] -> typing.Optional[X]
These two are useful. Especially the one with | since I think that's what most people would choose to write. I have no idea how easy or hard they are to implement.
Describe your issue
It seems that implementing generic union types (
X | Y
andUnion[X, Y]
) are difficult to implement and are rejected. We can try to implement reduced version containingNone
since it is often used instead oftyping.Optional[]
. We can transform it as follows:X | None
=None | X
->typing.Optional[X]
X | Y | None
=X | None | Y
=None | X | Y
->typing.Optional[object]
typing.Union[X, None]
=typing.Union[None, X]
->typing.Optional[X]
typing.Union[X, Y, None]
=typing.Union[X, None, Y]
=typing.Union[None, X, Y]
->typing.Optional[object]
This issue is specialised version of #4631
The text was updated successfully, but these errors were encountered: