[Python-Dev] [erratum] Emotional responses to PEPs 484 and 526 (original) (raw)
Guido van Rossum guido at python.org
Sat Sep 3 12:16:32 EDT 2016
- Previous message (by thread): [Python-Dev] [erratum] Emotional responses to PEPs 484 and 526
- Next message (by thread): [Python-Dev] PEP 526 ready for review: Syntax for Variable and Attribute Annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Sep 3, 2016 at 8:18 AM, Stephen J. Turnbull <turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:
Stephen J. Turnbull writes:
> My version ... furthermore makes mypy into a units checker, That isn't true, mypy does want annotations on all the variables it checks and does not infer them from initializer type.
But it does! Mypy emphatically does not need annotations on all variables; it infers most variable types from the first expression assigned to them. E.g. here:
output = [] n = 0 output.append(n) reveal_type(output)
it will reveal the type List[int] without any help from annotations.
There are cases where it does require annotation on empty containers, when it's less obvious how the container is filled, and other, more complicated situations, but a sequence of assignments as in Nick's example is a piece of cake for it.
In fact, the one place where I wanted a type annotation was here:
expected: V = Ohm(100k)*input
because I haven't had a need to use Ohm's law in a long time, so I could personally use the hint that Ohm times Amps makes Volts (but again, given suitable class definitions, mypy wouldn't have needed that annotation).
-- --Guido van Rossum (python.org/~guido)
- Previous message (by thread): [Python-Dev] [erratum] Emotional responses to PEPs 484 and 526
- Next message (by thread): [Python-Dev] PEP 526 ready for review: Syntax for Variable and Attribute Annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]