-
Notifications
You must be signed in to change notification settings - Fork 258
Add text about Type[C]. #218
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 and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This addresses #107 (but it doen't close it because the issue also calls for an implementation in typing.py).
@@ -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 | |||
---------- |
There was a problem hiding this comment.
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:
- 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.
Type[C]
has normal semantics of type: This is just a set of objects that respondTrue
toissubclass(objc, C)
.- 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".
- Finally, using such terminology could lead to proliferation of "meta": If we call annotations of values that are class objects by
Type[C]
or byABCMeta
meta-types, then how are we supposed to call annotations of values that are metaclasses (byType[ABCMeta]
for example)? Meta-meta-types? :-)
Miscellaneous things:
|
- Replaced section heading with "The type of class objects" and changed the opening sentence to match. - Drop "at runtime". - Replaced "is not allowed" with "is rejected by the type checker" (and then some). - Clarified that you can write Type[Union[...]] or Type[Any]. - Mentioned that a future PEP revision may deal with constructor signatures. - Clarified behavior when Type[Any] is used. - Clarify that Type[T] is covariant (though I'm not sure I understand the concept well enough here to explain it well -- by contrast, if Type[T] were invariant, what would change?).
Sent another omnibus update; please review! |
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 |
There was a problem hiding this comment.
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?
Clarified both in 2192c76. |
It looks good to me. I have no further comments. |
Looks good to me as well. |
This addresses #107 (but it doen't close it because the issue also
calls for an implementation in typing.py).