You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mypy should look in metaclass for operations on class objects #2413
Unsupported left operand type for >> ("StringWrapper")
However, __rshift__ is defined on StringWrapper AND on StringWrapper'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.
changed the title [-]"Unsupported left operand type for >>" while __rshift__ is defined[/-][+]Mypy should look in metaclass for operations on class objects[/+]on Nov 7, 2016
Activity
gvanrossum commentedon Nov 7, 2016
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.
sametmax commentedon Nov 7, 2016
Just tried, indeed with
StringWrapper() >> "foo", no more warning.[-]"Unsupported left operand type for >>" while __rshift__ is defined[/-][+]Mypy should look in metaclass for operations on class objects[/+]gvanrossum commentedon Nov 7, 2016
OK, I've changed the title accordingly (I don't think it's specific to
>>).elazarg commentedon Nov 12, 2016
Related: #2392
TRManderson commentedon Nov 18, 2016
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.
TRManderson commentedon Nov 18, 2016
Yep it's just metaclass stuff in general
ilevkivskyi commentedon Feb 7, 2017
It looks like this issue is now fixed by #2475
JukkaL commentedon Feb 7, 2017
The property, attribute and method examples now work.
__rshift__still doesn't seem to work:ilevkivskyi commentedon Feb 7, 2017
@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).
JukkaL commentedon Feb 7, 2017
I can confirm that this behaves differently for
intandstroperands. It may have something to do with integers also defining__rshift__and friends.elazarg commentedon Feb 7, 2017
Yes, it's failing for all types but the reverse method hides it for int. Maybe the lookup inhas_membershould be different.elazarg commentedon Feb 7, 2017
(Sorry, scratch the above: more likely is that the reverse method prohibits the lookup)
Check for member in type-fallback (#2822)
JukkaL commentedon Feb 7, 2017
#2822 fixed the remaining issue.