@mikeshardmind I would also mention typing.cast()
. No runtime effect, just an identity function.
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import cast
else:
cast = lambda typ, v: v
As an aside, several of these seem to (at runtime) reduce to an identity function of some sort, returning the input unchanged. We added a C version of this as _typing._idfunc
for use in typing.NewType.__call__
, perhaps this could be made public (operator.identity_function
?) for these sort of cases?