Making ``cast`` a built-in/keyword?

Hi all, Right now, I'm struggling a bit with the new Union syntax. It seems very important to keep in mind where it can be used and where it shouldn't be used. Some places I've seen where it can't be used: - In type aliases: `T = A | B` - When using a cast: `x = cast(A | B, y)` - In Pydantic models. - In NewType definitions: `T = NewType('T', A | B)` This means, that we have to teach our users to be very careful about this, and know when to use `Union[...]` or `Optional[...]` instead. So, about `cast()` specifically, I wonder whether it would make sense to turn that into a keyword, so that it doesn't evaluate the first argument at runtime, and is completely transparent. Would that be desirable? For the other situations, I'm not sure what we could do about those, beside quoting the type. Sorry if this has been brought up before. I wonder whether there's any consensus about this and what direction we want to go in the future? Thanks a lot, Jonathan

Thanks for the quick reply. It works indeed. No idea how I missed that the | operator is now implemented in `type.__or__`. This is really great! That solves all issues I had.

Thanks for the quick reply. It works indeed. No idea how I missed that the | operator is now implemented in `type.__or__`. This is really great! That solves all issues I had.
participants (3)
-
Jelle Zijlstra
-
Jonathan Slenders
-
Paul Bryan