microsoft / microsoft/vscode-mypy

incorrectly reports type error for union types in property setters

Open
#497 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug triage-needed
Dominant language
Python
Stars
150
Forks
39
Avg merge
21h 45m
Merged PRs (30d)
8

Description

## 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

```json
{
"mypy-type-checker.path": [
"C:\\Users\\GSWI\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\mypy.exe"
]
}
```

## Code Sample

```python
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:
1. The setter `x` accepts both `int` and `str` (union type `int | str`)
2. 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
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported false positive in VS Code using the provided Python property-setter example, then compare the extension's behavior with the command-line mypy result. Done means the assignment to a.x accepts the int | str setter type without an erroneous diagnostic; the payload does not name an implementation file or regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, vscode
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.