-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Incorrect overalp detected in __rmod__ with str argument #7402
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
Comments
I think this is a usability bug. Mypy is reporting something that's a legitimate issue/is legitimately questionable with your code, but is doing so in a fairly unhelpful way. Basically, the problem is that (Actually, there are a few exceptions to this rule: for example, if you make Regardless, mypy should do one of two things:
To answer your other questions:
|
Thank you for such a detailed and insightful response @Michael0x2a! In general I have no direct control over the code I annotate, but I guess this is something to push upstream (the actual module is mostly code-generated anyway). From where I stand that's definitely an usability issue. The actual annotation is a tad more complex and results in something around:
with little indication, where the actual problem lies. Getting an error indicating, that the code is unreachable, would be a huge improvement over that. |
Hi folks: I would like closing the issue, can I PR? |
@tapaswenipathak -- sure, go for it. The method you'll want to change is either the Also, it occurred to me a third option we could try exploring is by default not to report an error, and only report one if the user passes in the |
As of #17392, this works. |
Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new.
Flags used:
--python-version 3.7 --strict-optional --no-site-packages --show-traceback --no-implicit-optional
Problem occurs:
__mod__
/__rmod__
pair.__mod__
isUnion[T, str]
, whereT
can be self type, or some other type (let's sayint
).__rmod__
isstr
.__rmod__
is provided,Reproducible example:
yields
Issue is specific to
__mod__
/__rmod__
pair, i.e. this works just fine:and I haven't found any other problematic pair.
As far as I can tell it strictly depends on
other
beingstr
. For example this works just fineAdditionally, to reproduce the problem, we need a return type annotation on
__rmod__
, and removing it is sufficient to pass type check (removing return type annotation from__mod__
has no impact at all):though failure is not specifically caused by referencing self type, as for example this, will fail as well
The text was updated successfully, but these errors were encountered: