<div dir="ltr">Yeah, I've considered that, but it feels too punctuation-heavy (as does the C++ cast<T>(x)). Also, we need cast() to be a fast no-op; cast[T](x) necessarily means calling two functions rather than one.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 23, 2015 at 1:13 PM, Ryan Gonzalez <span dir="ltr"><<a href="mailto:rymg19@gmail.com" target="_blank">rymg19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Mon, Mar 23, 2015 at 2:55 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Sun, Mar 22, 2015 at 11:02 PM, David Foster <span dir="ltr"><<a href="mailto:davidfstr@gmail.com" target="_blank">davidfstr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">* It's a bit vague how local variables should be typed in the presence of<br>
multiple assignments. Consider:<br>
<br>
```<br>
if x > 0:<br>
root = sqrt(x) # type: int<br>
else:<br>
root = None<br>
```<br>
<br>
It seems that the type of `root` should be inferred as `Union[int, None]`<br>
(AKA `Optional[int]`), but there's no discussion about this type of<br>
inference in the PEP.<br>
<br>
Cases like this are the only way that the proposed blank `Undefined`<br>
value makes sense to me, using an example like:<br>
<br>
```<br>
root = Undefined # type: Optional[int]<br>
if x > 0:<br>
root = sqrt(x) # type: int<br>
else:<br>
root = None<br>
```<br></blockquote><div><br></div></span><div>Right. Another use case for Undefined is class variables (serving as instance variable initialization/declaration).<br><br></div><div>If you feel strongly that this needs to be mentioned in the PEP, can you send a PR to <a href="http://github.com/ambv/typehinting" target="_blank">github.com/ambv/typehinting</a> ? <br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* +1 for only allowing .pyi as the extension for stub files (and not also .py).<br>
Makes it very clear that they should only be interpreted as stubs.<br></blockquote><div><br></div></span><div>Perhaps. Though there are also downsides.<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* -1 that `Optional[T1]` is unnecessary. It's conceptually more clean and<br>
directly corresponds conceptually to types like `int?` and `?int` from<br>
other languages.<br></blockquote><div><br></div></span><div>Indeed, Optional[t] is much clearer to the human reader than Union[t, None].<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* +1 for the argument order cast(x, T). This is consistent with (x: T) elsewhere.<br></blockquote><div><br></div></span><div>I disagree on this. It goes against the argument order of casts in other languages, e.g. C, C++, Java, and even in Python -- you write int(x), not x(int).<br></div><div></div></div></div></div></blockquote><div><br></div></div></div><div>I brought this up somewhere before, but I still think this would be great for casts:</div><div><br></div><div>cast[T](x)</div><div><br></div><div>Like C++'s named casts (static_cast<T>(x), dynamic_cast<T>(x), etc.). It gives the notion that T is a type, not some random variable, and that cast is NOT a normal function call.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div></div><span>-- <br><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</span></div></div>
<br></span><span class="">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Ryan</div><div dir="ltr">[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.<br></div><div dir="ltr"><div><a href="http://kirbyfan64.github.io/" target="_blank">http://kirbyfan64.github.io/</a><div style="display:inline-block;width:16px;min-height:16px"> </div></div></div></div></div></div></div></div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)</div>
</div>