Problem Description
MyPy extension in VS Code incorrectly reports a type error, while mypy from the command line finds no issues.
Environment
- VS Code Version: 1.102.0
- MyPy Extension: mypy-type-checker
- MyPy Version: 1.20.0 (compiled: yes)
- Python Version: 3.12.10
MyPy Extension Configuration
{
"mypy-type-checker.path": [
"C:\\Users\\GSWI\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\mypy.exe"
]
}
Code Sample
class A:
_x: int = 0
@property
def x(self) -> int:
return self._x
@x.setter
def x(self, value: int | str) -> None:
self._x = int(value)
a = A()
a.x = "42" # ← VS Code MyPy extension reports error here
Expected Behavior
The code should pass without errors because:
- The setter
x accepts both int and str (union type int | str)
- MyPy from command line confirms the code is correct
Actual Behavior
VS Code MyPy Extension:
Incompatible types in assignment (expression has type "str", variable has type "int")
Command Line MyPy:
> C:\Users\GSWI\AppData\Local\Programs\Python\Python312\Scripts\mypy.exe main.py
Success: no issues found in 1 source file
Problem Description
MyPy extension in VS Code incorrectly reports a type error, while mypy from the command line finds no issues.
Environment
MyPy Extension Configuration
{ "mypy-type-checker.path": [ "C:\\Users\\GSWI\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\mypy.exe" ] }Code Sample
Expected Behavior
The code should pass without errors because:
xaccepts bothintandstr(union typeint | str)Actual Behavior
VS Code MyPy Extension:
Command Line MyPy: