<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 12, 2016 at 8:00 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Fri, May 13, 2016 at 12:52 PM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
> Great. We'll be able to move this very quickly once we decide whether it<br>
> should be called Type[C] or Class[C]. The original proposal is Type[C], and<br>
> it's nice because it's a pun on `type`, just like Tuple[...] is a pun on<br>
> `tuple` (and similar for List etc.). But OTOH it really annotates a class<br>
> object, not an abstract type. I still prefer Type[C] -- anyone want to argue<br>
> that we're making a mistake? (I know, nobody's listening, everyone's too<br>
> busy arguing that Path should inherit from str. :-)<br>
<br>
</span>ISTM Type is the more obvious name here. Python doesn't have class<br>
objects any more than it has def objects - it has functions and types.<br></blockquote></div><br></div><div class="gmail_extra">Well, actually, I call them class objects all the time... Plus PEP 484 (at least the recent revisions, though this has always been the BDFL-delegate's intention) tries to make a clear terminological between classes (the things you have at runtime) and types (the things that type checkers care about).<br><br>There's a big overlap because most classes are also types -- but not the other way around! E.g. Any is a type but not a class (you can neither inherit from Any nor instantiate it), and the same is true for unions and type variables. And it's pretty clear that when you have an argument or variable annotated with Type[C] it has to be a real class object, not Any or a union or a type variable, because in the common use case, functions taking class objects either instantiate that class, call class methods on it, or use it for isinstance() checks, and none of those things would work if at run time they received Any or a union or type variable.<br><br></div><div class="gmail_extra">Let's look at that function new_user() again:<br><br>def new_user(user_class: Type[User]) -> User:<br></div><div class="gmail_extra">    return user_class()<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">We can call new_user(ProUser) or new_user(TeamUser), but calling new_user(Any) isn't going to work at runtime, not us new_user(Union[ProUser, TeamUser]).<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Note also that this is a unique twist for Type[C] that doesn't exist for non-type annotations. If we have a function argument annotated with a class, e.g.<br><br></div><div class="gmail_extra">def first_name(u: User) -> str: ...<br><br></div><div class="gmail_extra">it's totally reasonable to call it with an argument whose type is Union[ProUser, TeamUser]:<br><br></div><div class="gmail_extra">def get_user_by_id(id: str) -> Union[ProUser, TeamUser]: ...<br></div><div class="gmail_extra">name = first_name(get_user_by_id('joe'))<br><br></div><div class="gmail_extra">This is because here the *type* returned by get_user_by_id() is a union, but the actual *values* it returns are always instances of one of the runtime classes ProUser or TeamUser.<br><br></div><div class="gmail_extra">If we had had more consistent terminology in Python from the start, this naming issue would never have come up -- we'd never have used type(x) as (almost) equivalent to x.__class__, and we wouldn't have used class C(type): ... to define a metaclass (i.e. a class's class).<br><br></div><div class="gmail_extra">But that's water under the bridge, and we might a well write Type[C] rather than Class[C] to pub with `type`. And it seems only two people care about the difference -- Mark Shannon and myself. :-) So Type[C] it is.<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>