4 ms·
types in python 3.5?! I had no idea -- that's exciting.
by eggie5 9y ago
types in python 3.5?! I had no idea -- that's exciting.
- williamstein 9y agoThis was a big contribution from Dropbox: http://blog.zulip.org/2016/10/13/static-types-in-python-oh-mypy/ http://blog.zulip.org/2016/10/13/static-types-in-python-oh-m...
- bpicolo 9y agoThe language itself supports annotations, without any actual typechecking. You use http://mypy-lang.org/ http://mypy-lang.org/ to get the static checking.
- shalabhc 9y agoThere is also Google's pytype: https://github.com/google/pytype https://github.com/google/pytype
- bpicolo 9y agoThat looks like it adds types rather than checks?
- shalabhc 9y agoIt does both. I can do some inference but definitely does type checking. Here's a Pycon talk from last year about pytype: https://youtu.be/IDm_YIQihhs https://youtu.be/IDm_YIQihhs
- bpicolo 9y agoIt needs severely more documentation, heh. Why would I use it over mypy, which appears to have a lot more community investment, thorough docs, and is somewhat official? It also doesn't support python3.6 so it doesn't know about format strings =/
- shalabhc 9y agopytype might work better in some cases, because it can do inference. But yes, it needs more docs.
- joobus 9y agoNote they are type annotations. They are for tooling/development only; the runtime doesn't care about the types at all.
- jrs95 9y agoThat's not entirely true. The information from the type annotations is available at runtime. ApiStar takes advantage of this, for example.
- ubernostrum 9y agoThe information from annotations is exposed to the runtime, but nothing in the runtime treats them as types or performs any type checking. The feature was introduced as a generic way to annotate functions, without being constrained to a single use case (type checking), and all the tools which actually do type-checking based on annotations are third-party.
- randyrand 9y agoC++ also does do any type checking at runtime. Compile time checking is all that really matters.
- ubernostrum 9y agoThe CPython implementation does have a "compile" step (to produce bytecode, which is what actually gets executed, by a simple stack-based virtual machine), and does not do any type checking in that step no matter how many annotations you give it.
- petre 9y agoHmm, Perl6 has real types, although they're completely optional.
- ice109 9y agowhich language's run time cares about types?
- seanwilson 9y agoAnybody have experience of using this? More info: https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html I've been using TypeScript a lot recently and it has had a big impact on reducing bugs and making refactoring easier so something similar for Python looks great.
- shalabhc 9y agoSee https://youtu.be/7ZbwZgrXnwY https://youtu.be/7ZbwZgrXnwY for a talk from the mypy team. Description: https://us.pycon.org/2017/schedule/presentation/678/ https://us.pycon.org/2017/schedule/presentation/678/
- stefanpie 9y agoThe types do the actually speed up execution but I find them useful in various parts of my codebase when I work on a project (for exaple when defining classes which represent more advanced and complex data types for my specific project). It help staying organized and making sure your not ambiguously passing in wrong data types. Also pycharm uses them to understand custom classes and functions you define and provide suggestions.