-
-
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
Offer a simpler way to resolve metaclass conflicts #14033
Comments
As I played further with it, I found that annotating |
Right now So, it has Your ideas seem reasonable. Do you want to work on it? :) |
This problem was previously discussed in python/typeshed#1595 |
I'm happy to contribute. a) I haven't contributed to mypy before, so I wouldn't exactly know where to start, guidance welcome b) Can you elaborate on "Your ideas seem reasonable"? I'm not sure which of the two approaches I mentioned you'd like to see me implement. If the first one: I wouldn't know where to start looking. Judging by what AlexWaygood wrote, this seems to not be solvable in mypy, but typshed which again would need extended typing features in Python itself... so that seems a little unfeasible to me? I'm happy to jump into a chat somewhere to talk about the details, if you want to help me getting started. |
There are two cool ideas in this:
@robsdedude you can schedule a meeting if you want: https://calendly.com/sobolevn/ Don't worry that it says 2hours (we can do much faster). I will guide you through the contribution process :) Or drop me an email: |
@robsdedude meeting notes:
|
Digging further into it and working on improving the error experience (including the message) as discussed in our meeting, I'm looking at What do you think about only emitting a metaclass conflict at the place it's introduced at? This poses some technical difficulty as it's unclear, which metaclass mypy should assume for a class it considered having a metaclass conflict. But I think this can be resolved by traversing the mro and accepting the first explicitly declared metaclass as truth while falling back to Thoughts on this proposal? |
@sobolevn, you said "So, it has ABCMeta metaclass according to the typeshed". Where is |
Another thing to discuss: changing the error code is a breaking change. For users that have silenced mypy complaining about metaclass conflicts ( Moreover, I noticed that changing the error code didn't make any tests fail. So it appears there are no tests for those, are there? |
In my opinion changing codes from Because it adds more context to it. And changing failing places is rather easy for end users. |
@erictraut yes, this is something I will investigate. Thanks! |
For the record: I found that class M1(type): pass
class M2(type): pass
class Mx(M1, M2): pass
class A1(metaclass=M1): pass
class A2(A1): pass
class B1(metaclass=M2): pass
class C1(metaclass=Mx): pass
class D(A2, B1, C1): pass While the interpreter is, rightfully so, not amused.
I'll see if I can also address this bug as it is very much related. Note for myself: |
Reading Python's documentation it seems mypy should actually be right and Python should accept Can someone shed some light on which one is the case? |
I think the interpreter is correct here. Mypy should flag As you noted, if you change the order of the base classes for |
Sorry for the notification, but I've been waiting patiently for my PRs to get reviewed without luck. Could somebody please have a look before they go even more stale and have even more merge conflicts? |
@JukkaL reaching out to you because you are the top contributor for this repository. Could you please help get this PR reviewed and merged as a lot of us are facing issues due to this. |
Feature
Consider the following minimal example
As of
0.990
, mypy complains about thisSame if I use
or
instead
Pitch
I propose 2 alternatives to help users deal with this
tuple.__class__ is type
and that this is fine (preferred)# typing: ignore
to resolve such cases.Technically, this is already possible today, but I suggest 2 improvements:
# typing: ignore[misc]
it. I'd like to mention that this feels pretty broad of an exception and might hide other real problems. Since this is an area where mypy might be overly restrictive and a workaround might be necessary, it should maybe be in a less broad category.MyTuple
which can be frustratingly tedious. Maybe there should be away to tell mypy "ok, you might not understand this, but trust me that this classMyTuple
has a valid metaclass, assume so for all child classes".The text was updated successfully, but these errors were encountered: