-
-
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
Overloads do not take type: ignore
into account
#12454
Comments
A |
Ah sorry, I was being a bit unclear with my terminology: not sure how to say it exactly but that probably shouldn't fail (function -> overload shouldn't be a breaking change, imo). Mainly, I'm referring to this that mypy uses to check overloads are ok not taking type ignores into account: Lines 1763 to 1771 in 14de8c6
If it should fail, my bad! |
The error comes from line 18, which starts with run_job( # type: ignore
job,
"",
) |
That doesn't solve the issue
The first error is still wrong and now mypy doesn't ignore the second one anymore. The only option other option would be this run_job(job, "") # type: ignore[arg-type] That would simply hide both errors instead of resolving the underlying issue. In the particular case it wouldn't be possible due to formatting constraints. -- |
Thought about this some more. I'm not sure how mypy, or any other type checker, is supposed to choose between overloads if one argument type is incorrect. Overloads simply depend on the arg-types. An even simpler example @overload
def func(var: int) -> int: ...
@overload
def func(var: float) -> str: ...
def func(var: float) -> int | str: ...
reveal_type(func(
"Hello" # type: ignore[arg-type]
)) What should mypy infer here? Currently it's I think we can close this issue. |
Maybe I'm missing something, but I also don't think there's a bug here. mypy passes if you use this instead: run_job( # type: ignore[call-overload]
job,
"",
) As @erictraut said, there is no notion of "passing" a type ignore into a call; the comment simply suppresses type errors on that line. In this case, we generate the error on the first line of the call, so that's where you have to put the ignore. |
Bug Report
When matching overloads, a
type: ignore
is not passed into the underlying type check.To Reproduce
Have this code:
Expected Behavior
Type checks fine.
Actual Behavior
Your Environment
mypy.ini
(and other config files): noneOriginally reported by @cdce8p in #11847.
The text was updated successfully, but these errors were encountered: