Add text about Type[C]. by gvanrossum · Pull Request #218 · python/typing (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation13 Commits4 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

gvanrossum

This addresses #107 (but it doen't close it because the issue also
calls for an implementation in typing.py).

Guido van Rossum added 2 commits

May 13, 2016 12:27

This addresses #107 (but it doen't close it because the issue also calls for an implementation in typing.py).

ilevkivskyi

@@ -861,6 +861,73 @@ allow all operations on it, and a value of type ``Any`` can be assigned
to a variable (or used as a return value) of a more constrained type.
Meta-types
----------

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "Meta-types" is not a good name for this section for four reasons:

  1. This could add to the classes vs. types confusion: Unlike metaclasses that are quite different from classes, types do not have such hierarchy, since one should not type annotate types, one can only type annotate classes.
  2. Type[C] has normal semantics of type: This is just a set of objects that respond True to issubclass(objc, C).
  3. I think someone who is looking for a documentation of this feature will not look for "Meta-types", therefore I would propose to change this to a simpler title, like "Type annotating class objects".
  4. Finally, using such terminology could lead to proliferation of "meta": If we call annotations of values that are class objects by Type[C] or by ABCMeta meta-types, then how are we supposed to call annotations of values that are metaclasses (by Type[ABCMeta] for example)? Meta-meta-types? :-)

@JukkaL

Miscellaneous things:

@gvanrossum

Sent another omnibus update; please review!

ilevkivskyi

rejected by the type checker (in addition to failing at runtime
because you can't instantiate a union).
Note that it *is* legal to use a union as the parameter for

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, you mean here "a union of classes", since in general Union can accept Tuple, Callable etc. If yes, then maybe it is better to mention this?

@gvanrossum

@ilevkivskyi

It looks good to me. I have no further comments.

@JukkaL

Looks good to me as well.