<p dir="ltr">Hi all,<br>
Has the syntax for specifying type been fully decided on already? </p>
<p dir="ltr">Using brackets may confuse new Python programmers. Since specifying type in Python is fairly new anyway, what do you all think of introducing angle brackets into Python instead? Other languages use angle brackets to specify types. It provides a good separation between type specification and list indexing.</p>
<p dir="ltr">I'm also worried that using square brackets will cause confusion as that notation is generally associated with array declarations in other languages. Even in Python, MyClass[int] may be confused with getting a key called int from some MyClass.</p>
<p dir="ltr">dict<str, int> seems to tell me more explicitly that I'm dealing with a declaration of an expected type. dict[str, int] looks very much like I'm getting an item (str, int) from some class. </p>
<p dir="ltr">The angle bracket (or any other suggestions you have in mind) provides a more concrete separation between when we are performing item indexing and when we're specifying a type to validate. </p>
<p dir="ltr">Sunjay</p>
<div class="gmail_quote">On Aug 15, 2014 1:55 PM, "Guido van Rossum" <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Doesn't seem a big deal. The only place where you'd see an implementation of optional() would be in typing.py, and optional(None) is redundant anyway.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Aug 15, 2014 at 10:51 AM, Petr Viktorin <span dir="ltr"><<a href="mailto:encukou@gmail.com" target="_blank">encukou@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><div>On Fri, Aug 15, 2014 at 7:36 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br>
> On Fri, Aug 15, 2014 at 10:19 AM, Petr Viktorin <<a href="mailto:encukou@gmail.com" target="_blank">encukou@gmail.com</a>> wrote:<br>
>><br>
>> On Fri, Aug 15, 2014 at 7:00 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>><br>
>> wrote:<br>
>> > On Fri, Aug 15, 2014 at 9:48 AM, Petr Viktorin <<a href="mailto:encukou@gmail.com" target="_blank">encukou@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Fri, Aug 15, 2014 at 5:55 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>><br>
>> >> wrote:<br>
>> >> ...<br>
>> >> >> Also... Does None magically mean NoneType in type definitions?<br>
>> >> ><br>
>> >> > Yes.<br>
>> >><br>
>> >> This would mean either that `(None | None) is None`, or that (x |<br>
>> >> None) is not always "optional x".<br>
>> >> And if type objects grow any other common functionality, None will<br>
>> >> have to support that as well.<br>
>> ><br>
>> ><br>
>> > Perhaps None itself should not implement any of this, and the __ror__<br>
>> > method<br>
>> > on ABCs should implement it. That way, None|Mapping and Mapping|None<br>
>> > would<br>
>> > both work, yet None|None would still be the TypeError it is today.<br>
>><br>
>> ... and that (x|None) does not always mean "optional x".<br>
>> Is this case special enough?<br>
><br>
><br>
> I'm not following. The proposal seems to be to add __or__ and __ror__<br>
> methods to type itself requiring the other argument to be also a type, or<br>
> the special case None (which is a value, not a type).<br>
<br>
</div></div>My concern is that if someone does programmatic type declaration<br>
manipulation/generation, there's now a special case to keep in mind.<br>
Instead of<br>
<br>
def optional(t):<br>
return t | None<br>
<br>
it's now:<br>
<br>
def optional(t):<br>
if t is None:<br>
return t<br>
else:<br>
return t | None<br>
<br>
because unlike other type declarations, None doesn't have __or__, or<br>
any other operation that types will gain in the future as this<br>
proposal matures.<br>
<br>
But maybe this is will never be a valid use case?<br>
</blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)
</div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">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></blockquote></div>