-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Mypy should look in metaclass for operations on class objects #2413
Comments
Does this work as expected when the left arg is not a class? I suspect mypy is treating classes specially somehow and not looking at the metaclass. |
Just tried, indeed with |
OK, I've changed the title accordingly (I don't think it's specific to |
Related: #2392 |
A large source of "errors" for me is using metaclasses for class properties, here's a minimal example:
I suspect it'll apply for anything to do with metaclasses though (as Guido suggested), given the two examples here are pretty disparate. |
Yep it's just metaclass stuff in general
|
It looks like this issue is now fixed by #2475 |
The property, attribute and method examples now work.
|
@JukkaL Hm, this is very strange, I tried this:
And it works (note that I use a string, like in OP example, not an integer). |
I can confirm that this behaves differently for |
|
(Sorry, scratch the above: more likely is that the reverse method prohibits the lookup) |
#2822 fixed the remaining issue. |
Mypy complains about this line:
StringWrapper >> "foo"
With:
Unsupported left operand type for >> ("StringWrapper")
However,
__rshift__
is defined onStringWrapper
AND onStringWrapper
's metaclass.I understand the notation seems strange, calling shift on a class, but I'm making a library in which this API makes sense. The related code works, and applying
>>
does call__rshift__
on the metaclass. The only problem is mypy mentioning it. I can force ignore it, but I wish that dev using my lib won't have to do so.The text was updated successfully, but these errors were encountered: