[Python-ideas] PEP 484 (Type Hints) -- second draft
David Foster
davidfstr at gmail.com
Mon Mar 23 07:02:40 CET 2015
* It's a bit vague how local variables should be typed in the presence of
multiple assignments. Consider:
```
if x > 0:
root = sqrt(x) # type: int
else:
root = None
```
It seems that the type of `root` should be inferred as `Union[int, None]`
(AKA `Optional[int]`), but there's no discussion about this type of
inference in the PEP.
Cases like this are the only way that the proposed blank `Undefined`
value makes sense to me, using an example like:
```
root = Undefined # type: Optional[int]
if x > 0:
root = sqrt(x) # type: int
else:
root = None
```
* +1 for only allowing .pyi as the extension for stub files (and not
also .py).
Makes it very clear that they should only be interpreted as stubs.
* -1 that `Optional[T1]` is unnecessary. It's conceptually more clean and
directly corresponds conceptually to types like `int?` and `?int` from
other languages.
* +1 for the argument order cast(x, T). This is consistent with (x: T)
elsewhere.
--
David Foster
http://dafoster.net/
P.S. Apologies if this doesn't add to the message chain correctly.
There's no clearly correct way to reply to a digest email from Mailman.
More information about the Python-ideas
mailing list