4 ms·
> But, because type hints are just window dressing in Python, Type annotations are not window dressing in a Python workflow using typechecking tools over the f
by dragonwriter 5y ago
> But, because type hints are just window dressing in Python,
Type annotations are not window dressing in a Python workflow using typechecking tools over the final code base, unless you explicitly tell the typechecker to ignore a detected error.
It's true that a type annotated library can't necessarily rely on downstream clients to have type discipline, and some library packages may not be fully annotated, which may create gaps to address.
> If I want to use types to enforce things, I'd prefer to use a language designed for that.
Python's type annotations were designed largely to make Python compatible with a separate existing language designed for that purpose; there's a reason mypy’s domain is mypy-lang.org
> What this article talks about (Protocol) seems to be at least an improvement in that regard, as you can worry about what your function does instead of what your types do.
Protocols are types; specifically, they are structural types.
- DerArzt 5y agoTo add to this, when we are reading/writing python source code there are types involved. The question becomes do we want the types to exist only in our heads or also denoted in the source. To me even though the type annotations don't provide the same kind of guarantees that the type system of say Haskell does, they do increase the readability of the source code. Finally (and this is more of my workflow), I utilize a build tool that has a mypy --strict call that will check my type annotations and alert me when things don't match up.