-
-
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
False negative: Incorrect return type overlooked when it is an alias to Union[T, …] #15803
Comments
I think mypy is doing the right thing here. You're using type variables incorrectly. The signature The statement The same logic applies to your other examples that use type variable In general, if a type variable appears only once within a function signature, you are using the type variable incorrectly. |
Bug Report
This may be related to #12211.
When extracting a type annotation like
-> t.AnyStr | int
to at.Union
alias, mypy fail to detect incorrect return types.The actual problem for me was that annotating flask view functions with
ResponseValueType
did not find obvious return type violations, but (as I found out during writing of this issue) a workaround seems to have been added.I'm unsure what to expect of mypy here but silently allowing everything seems like a big hazard to me.
To Reproduce
See the functions
foo2
andbar2
in the following gist:https://mypy-play.net/?mypy=latest&python=3.11&gist=04f598b90124f58021cf19209a7df967.
Expected Behavior
the return statements of
foo2
andbar2
should cause an error, either the same error asfoo
andbar
or the same asfoo3
andbar3
.Actual Behavior
foo2
andbar2
don't cause an errorYour Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: