Open gjcarneiro opened 8 months ago
Mypy's behavior is correct and compliant with the Python typing spec. The type list[Any]
is "consistent with" list[int]
(or any other list
). The Any
type allows for "gradual typing". You can think of Any
as "any type that could conceivably satisfy the type relationship".
And neither --disallow-any-generics
or --warn-return-any
triggers any kind of warning?... That's disappointing :disappointed:
Eric is right in general, but I do think it's worth considering whether mypy's --warn-return-any
option should have triggered here, which aims to cover this sort of issue. If you're interested, feel free to try making this change in a PR and we can see the fallout. (It might lead to an unacceptably high number of low-signal errors.)
Bug Report
(A clear and concise description of what the bug is.)
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict%2Cdisallow-any-generics%2Cwarn-return-any&gist=35cfbe4d01eed0422eb72869846095c1
Expected Behavior
I would expect an error on line 6
return x
. The function is declared to returnlist[int]
but is returninglist[Any]
.Actual Behavior
No error.
Your Environment
--strict --disallow-any-generics --warn-return-any
mypy.ini
(and other config files): (none)