-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
type
builtin function should return an instance of typing.Type
?
#1758
Comments
I think mypy would have to special-case Are you interested in trying to fix this? I expect complications in the On Mon, Jun 27, 2016 at 9:08 PM, Michael Lee [email protected]
--Guido van Rossum (python.org/~guido) |
(For the record: I've talked to @gvanrossum offline and am currently working on this) |
Is there some reason we shouldn't make the general case of |
I would expect it to work in general, but maybe the problem is that |
Yes general case already works (it's the reason The definition of I don't think we can express this fully by clever overloads in a stub; mypy must understand that |
This commit is a fix for python#1758 -- it special-cases the single constructor `type` builtin function within mypy so it returns an instance of `typing.Type` rather then just the generic `type` object.
I've run into a snippit of code which essentially boils down into this:
The behavior I was expecting was for
t
to be of typeType[SomeObject]
-- instead, it's of typetype
, due to howtype
is annotated in Typeshed:I attempted modifying the definition in Typeshed by first changing
__new__
to have the signaturedef __new__(cls, o: _T) -> Type[_T]
, but that had no effect. I then tried commenting out both__init__
s entirely in case mypy was defaulting to looking at those, but that also did nothing. I'm not entirely sure why the change to__new__
isn't working, though it may be related to issue 1020?I did find a workaround for this particular case by doing:
...but it would be nice if
type
could be changed so this casting is unnecessary, though I'm not entirely sure how this would be done.The text was updated successfully, but these errors were encountered: