Tom Ritchford
Oct 4, 2023

--

I only embraced type hints in the last couple of years, and they're pretty good, worth the effort, but not perfect.

Unlike other strongly-typed language I have used, there have been cases where getting the correct typing has so far proven impossible.

I know a lot of tricks now, like `if typing.TYPE_CHECKING:` but there is a hardcore 2% of the code that I can't get the typechecking to work on.

Here's an example: https://github.com/rec/dtyper/blob/main/dtyper.py#L220-L265

Now, the code does have type hints, but the resulting dataclass is not understood by mypy at least, so I get attr-defined errors in client code.

Oh, and also this issue which I forgot about until now.

That said, I would never go back to writing Python without type hints!

--

--

Responses (1)