microsoft / microsoft/pyright

Type inference didn't take into account instance field being changed in method

Open
#11,380 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

## Environment data

- Pylance version: 2025.6.2
- OS and version: Mac 14.7.5
- Python version (& distribution if applicable, e.g. Anaconda): 3.13

## Code Snippet

```python
class Test:
def __init__(self) -> None:
self.val: bool = True
def set_val(self, valP: bool) -> None:
self.val = valP

test = Test()
test.val = True
test.set_val(False)
test.val
```

## Repro Steps

1. Paste the above snippet into vscode

## Expected behavior

Hovering over `test.val` at the end will give a type hint that it's a bool.

## Actual behavior

Image

## Logs

```
XXX
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the Python snippet in VS Code with Pylance 2025.6.2 and inspect the inferred type shown for the final `test.val`. Start by tracing the type-inference behavior for the instance field after `set_val(False)`. Done means the final hover reports `bool` while existing inference behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.