3 ms·
Exactly, it’a brilliant that they designed a system where the annotations themselves can be dynamic and read at runtime, it has so much potential for interestin
by samwillis 5y ago
Exactly, it’a brilliant that they designed a system where the annotations themselves can be dynamic and read at runtime, it has so much potential for interesting things. But MyPy completely hobbles it by preventing all the dynamic potential, even if MyPy had an escape hatch to say ignore anything derived from this type as it’s not possible to describe statically that would be better than nothing.
It unfortunately leaves you with a choice of either taking advantage of dynamic annotations or using MyPy, but not both.
And as the sibling comment says, typescript did it so much better.
- probablyrobert 5y agoThere is actually an escape hatch you can use, although it is a bit clunky: ```py from typing import TYPE_CHECKING if TYPE_CHECKING: Foo = "expression that mypy can understand" else: Foo = "dynamic expression" ```
- samwillis 5y agoSomehow in all my searching the other day I missed that, thanks!
- BerislavLopac 5y agoPython also offers structural typing, which is both dynamic and mypy-compatible.