Typed Python: new Mypy release
mypy-lang.blogspot.com
mypy-lang.blogspot.com
https://vimeo.com/74354480 linked to from: http://games.greggman.com/game/dynamic-typing-static-typing/ linked to from: https://news.ycombinator.com/item?id=10933524
The (now documented) --silence-imports option will remove the most frequent use for ignoring types though.
This project is very similar to TypeScript or Flow and I have found it provides a similar huge boost in reliability.
No type checker was one of the bigger flaws in Python.
When in Groovy, I use type checker in public functions and APIs. It is a good communication tool.
In my opinion, Python is better than Groovy. This feature still make it better.
@Grab(group='foo', module='bar', version='1.0.0')
at the top of randomscript.groovy you will have bar available to import by the time the script starts.import pip
pip.main(['install', 'bar'])
import pip
pip.main(['install', '--user', 'bar'])
which throws an error, e.g., if bar is already installed, meaning you will have to wrap the calls to pip.main() in a "try" block and differentiate between the types of errors they throw.The above already makes it noticably less convenient for a script to manage its own dependencies. The killing blow, however, comes form the fact that pip won't let you install multiple versions of the same package in parallel: the most recently installed version overwrites the previous one. This means that a script that relies on a per-user package store can only be safe if it checks the version of every package it uses and replaces it if needed each time it is run. This can a take a long time and is error prone (what if your Internet connection goes down?) but the alternative is simply to deal with the brittleness.
I can see this being solved for Python but the solution will probably involve automatically creating and caching per-script virtualenvs. For now, though, something like PyInstaller (i.e., binaries) remains more practical if you want to distribute standalone Python scripts.
I'll be happy to discuss this further if anyone shows interest.
python as a first language? no problem. scala as a first language? you've got to be kidding me...
https://docs.python.org/3/library/typing.html
The PEP 484 proposal:
I wish we could just use mypy when we feel like making our code faster :/
(Typing is optional)
Of course. Examples:
▶ ocaml
OCaml version 4.02.3
# 9;;
- : int = 9
▶ ghci
GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> 9
9
Prelude> :t 9
9 :: Num a => a
Prelude>
▶ drracket
Welcome to DrRacket, version 6.3.0.2--2015-10-28(-/f) [3m].
Language: typed/racket; memory limit: 128 MB.
> 9
- : Integer [more precisely: Positive-Byte]
9
▶ scala
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_91).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 9
res0: Int = 9
There are even interpreters for C (http://www.drdobbs.com/cpp/ch-a-cc-interpreter-for-script-co...).tl;dr: you can have a REPL in both statically and dynamically typed languages.
I think the question you mean -- which I'm also interested in the answer to -- is: How can a dynamically typed language be statically type checked? Presumably Hindley-Milner style inference doesn't/can't work. Do static analysers such as Mypy therefore trace the execution of the code until it finds something that conflicts? Are there cases where this approach won't work, either technically or practically?
Via runtime tags, which are not the same as types.
(Barking at the wrong tree intensifies.)
What are you talking about? MyPy has supported generics since before the 0.1 release: https://github.com/python/mypy/blob/v0.1.0/docs/source/gener...