Skip to content

Tuple and Callable should be listed as generic variants of builtin classes #212

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

Closed
ilevkivskyi opened this issue May 6, 2016 · 5 comments

Comments

@ilevkivskyi
Copy link
Member

Currently Callable and Tuple are listed in the section "Fundamental building blocks", I would rather move them to "Generic variants of builtin classes". Indeed, Callable[..., [Any]] could be just equivalent to collections.abc.Callable (See also this comment #133 (comment)), and Tuple[Any, ...] could be just equivalent to tuple, in the same way as List[Any] is an equivalent of list.

Also, although Optional is just a particular case of Union, maybe it should be listed in the section "Fundamental building blocks" for completeness.

@gvanrossum
Copy link
Member

gvanrossum commented May 6, 2016 via email

@ilevkivskyi
Copy link
Member Author

You see this more from the position of implementation, I see this more from the position of interface. Probably you are right, Callable is indeed quite special. Probably the division in PEP that exist now, could be reformulated to distinguish between "Special typing constructs" and "Generic type constructs and types" (for example). Let me explain why I think so.

This qestion appeared in the context of compromise that I discussed in #136 , namely we always raise TypeError in instance and subclass checks for special type constructs like Any, Union, etc. But probably we should allow them for generics without parameters, so that the question is whether we should allow issubclass(cls, Callable) (considering Callable a generic type construct) or prohibit this (considering Callable a special type construct). I think that we should allow this, because as you reasonably mentioned in #133

Pretty much anything you can do with collections.abc.X should be possible with typing.X

If you agree, I could make a PR to change the formulation in PEP

@gvanrossum
Copy link
Member

gvanrossum commented May 6, 2016 via email

@ilevkivskyi
Copy link
Member Author

@gvanrossum I have submitted a PR #214 . Finally, I decided, that it is better to just be more precise about subclasses vs subtypes, remove the mention of issubclass in the description of Union, and add a note that it should not be used with special type constructs.

In this way I am OK with keeping the current structure of sections in PEP describing typing.py and the results of discussion in #136 could be easily added to PEP independently later (if necessary).

@ilevkivskyi
Copy link
Member Author

Fixed by #214

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

No branches or pull requests

2 participants