5 ms·
Python 3.6 introduced type checking as an option, so you can hack something together in Python, then add types later.
by Tijdreiziger 8y ago
Python 3.6 introduced type checking as an option, so you can hack something together in Python, then add types later.
- DonaldPShimoda 8y agoType hints aren't checked or enforced by the compiler. They're really just special-syntax comments to help the developer (or IDE, as the case may be). I wouldn't call this "type checking".
- Tijdreiziger 8y agoYou can run a type-checking tool (e.g. mypy) which will tell you if you've made any type errors. Since Python has no 'compile' step, type-checking takes the place of compiling in other languages.
- uryga 8y agoI'm using the type annotations from `typing` in a Python 3.5 project I'm working on, but only as a form of documentation. Unfortunately mypy doesn't work for me – the project heavily uses a namedtuple-style sum type library, and I haven't found a way to make the types it generates work with mypy. (iirc mypy has builtin support for namedtuple, but doesn't really support other types generated at runtime)