4 ms·
“At the same time, developers still see value in writing type annotations as they serve as documentation.” Also useful for autocomplete. For me, most of the v
by zackees 6y ago
“At the same time, developers still see value in writing type annotations as they serve as documentation.”
Also useful for autocomplete.
For me, most of the value of typing is at the function level: what does this function accept as input and what does it produce as output?
Also mypy gets in the way of using loop constructs, as the iterating variables have to be predeclared with typing before the loop, breaking encapsulation.
- karlicoss 6y agoHmm, what do you mean? If you type the thing you're iterating over, the type of variable will be inferred?
- emptysea 6y agoI'm curious what you mean by "iterating variables have to be predeclared". In my experience mypy's type inference works with bog standard python constructs like a for loop that appends into a list that gets declared before the loop, aka: output = [] for x in range(1): output.append(x) reveal_type(output) # note: Revealed type is 'builtins.list[builtins.int*]'
- zackees 6y agomypy will complain that x is type Any when checking assignments. To silence the warning one has to do: x: int for x in range(1): ...
- codethief 6y agoMaybe they're referring to the fact that if you do `for x in y` and y isn't properly annotated, then you will need to write x: MyType for x in y: ... for x to be annotated properly.