Skip to content

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

Merged
merged 4 commits into from
May 18, 2016
Merged

Add text about Type[C]. #218

merged 4 commits into from
May 18, 2016

Conversation

gvanrossum
Copy link
Member

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).
@@ -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
----------
Copy link
Member

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
Copy link
Contributor

JukkaL commented May 16, 2016

Miscellaneous things:

  • Type[T] should likely be covariant, as discussed before.
  • Treatment of __init__ signatures is going to be nontrivial, as discussed in the issue. Perhaps mention that may require a future PEP update? In particular, we discussed the variant Type[[A, ...], C] which would be like Type[C] but with __init__ constrained to supporting positional arguments A, .... This would be an alternative for Callable that is also a type object. Is this potentially going to be included in phase 2?

- 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?).
@gvanrossum
Copy link
Member Author

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
Copy link
Member

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
Copy link
Member Author

Clarified both in 2192c76.

@ilevkivskyi
Copy link
Member

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

@JukkaL
Copy link
Contributor

JukkaL commented May 18, 2016

Looks good to me as well.

@gvanrossum gvanrossum merged commit 39c07e8 into master May 18, 2016
@gvanrossum gvanrossum deleted the typec branch May 19, 2016 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants