Closed stephenskett closed 3 weeks ago
If --warn-return-any
(part of --strict
) is given, this errors: issue18112.py:14: error: Returning Any from function declared to return "T" [no-any-return]
.
If those strict flags are not given, mypy is correct to accept this code. Using Any is unsafe; that's what Any is for.
Oh, whoops! Should've spotted that. Thanks for clarifying, and keep up the great work! 🙌
Bug Report
N.B. I think this bug may be related to Issue #12290, but thought I'd report it anyway, in case it is considered sufficiently different to be worth investigating separately.
It appears to be possible to arbitrarily "override" the type of an untyped variable (i.e. type
Any
) to any concrete type via a function annotated using aTypeVar
, even if the type inside the function scope is not narrowed at all (as per the exampledoesnt_actually_check_anything
function below). [Obviously not common to write a function that doesn't do anything except override a type; but common-sense dictates that MyPy should be able to detect this!]To Reproduce
Expected Behavior
MyPy detects non-narrowed type on l.14 and produces e.g.
return-value
error.Actual Behavior
MyPy passes. If l.26 is uncommented, an
attr-defined
error is detected.Your Environment