If you believe type hints in Python are a net negative, then just don't use them.
I also don't get the performance argument: Type hints aren't evaluated at runtime, so whether code has them or not shouldn't matter for performance.
If you believe type hints in Python are a net negative, then just don't use them.
I also don't get the performance argument: Type hints aren't evaluated at runtime, so whether code has them or not shouldn't matter for performance.
> I also don't get the performance argument: Type hints aren't evaluated at runtime, so whether code has them or not shouldn't matter for performance.
Type hints actually are evaluated at runtime, since they're part of the syntax tree. They just aren't checked for correctness, so the (small, but sometimes non-negligible) amount of parsing overhead they add is essentially lost performance.
The correct way would be to do conditional imports that are only performed while typechecking in this case. But I'd expect the issue to happen often.
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import mymodule
def myfunc(arg: mymodule.MyType) -> bool:
return bool(arg)
This will make type annotations to be converted internally to strings. TYPE_CHECKING is a constant that's always false except when you use a type checker, so mymodule will never be imported on runtime, but the type checker will think that it was imported. from __future__ import annotations
This will break all the runtime type checking modules (such as typedload, which I wrote).Most runtime type checking modules I am aware of support
from __future__ import annotations
E.g., typeguard, Pydantic, beartype, among others.When I had complained earlier, Guido didn't give 2 shits, although it broke typedload, a library I wrote that is very similar to pydantic, when pydantic didn't exist.
So I know what I am saying
I hate this spin to somehow make it about not trusting developers to do their job right. As if it was an insult to test for correctness. Imagine skipping pre-flight checks for accomplished pilots, or load calculations for renowned bridge engineers.
This hubris of some software developers assuming to be hyper-correct geniuses really alienates me.