What does typing.cast do in Python?

From the documentation (emphasis mine):

Cast a value to a type.

This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible).

The “casting” only takes place in the type-checking system, not at runtime.

Leave a Comment