You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a mapping with an Optional value type, accessing a value using a variable key instead of a literal key prevents a None check from working properly.
mypy should not output any errors. As the above example shows, using a string literal instead of a variable containing a string does not cause any errors, even though the code is otherwise identical. The "Optional types and the None type" section of the documents says "supported checks for guarding against a None value include if x is not None", so this code should work.
Actual Behavior
mypy outputs the following:
test.py:11: error: Argument 1 to "func" has incompatible type "Optional[str]"; expected "str" [arg-type]
Your Environment
Mypy version used: 0.812
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): show_error_codes = True
Python version used: 3.7.9
Operating system and version: macOS 10.15.7 (19H524)
The text was updated successfully, but these errors were encountered:
Using Final (from typing_extensions) for both FOO and data was one of the first things I tried, but I didn't include it in my example because it didn't change the error message at all.
Bug Report
When using a mapping with an
Optional
value type, accessing a value using a variable key instead of a literal key prevents aNone
check from working properly.To Reproduce
test.py
:mypy test.py
Expected Behavior
mypy should not output any errors. As the above example shows, using a string literal instead of a variable containing a string does not cause any errors, even though the code is otherwise identical. The "Optional types and the None type" section of the documents says "supported checks for guarding against a
None
value includeif x is not None
", so this code should work.Actual Behavior
mypy outputs the following:
test.py:11: error: Argument 1 to "func" has incompatible type "Optional[str]"; expected "str" [arg-type]
Your Environment
0.812
mypy.ini
(and other config files):show_error_codes = True
3.7.9
The text was updated successfully, but these errors were encountered: