microsoft / microsoft/pyright

Erroneous "undefined variable" after specific method call

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

Description

Pylance version: 2025.8.3

OS: Linux Mint 21.3 Cinnamon 6.0.4

Visual Studio Code version: 1.105.0

Python version: 3.13

I'm using `pysmb` v1.2.13 and pylance is reporting an undefined variable.

The minimal (though unrunnable) code that shows this is:

```python
from smb.SMBConnection import SMBConnection

with SMBConnection(...) as con:
con.connect(...)
con.listPath(...) # <-- pylance reports "reportUndefinedVariable" for "con"
```

It's happy with the previous line, so...?

Incidentally, it's happy with this:

```python
from smb.SMBConnection import SMBConnection

with SMBConnection(...) as con:
con.disconnect(...)
con.listPath(...) # <-- No warning here.
```

and also with this:

```python
from smb.SMBConnection import SMBConnection

with SMBConnection(...) as con:
con.foo()
con.connect(...)
con.listPath(...) # <-- No warning here.
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal Python reproduction in the issue and compare the `connect`, `disconnect`, and `foo` call sequences inside the `with` block. Trace Pyright's handling of the `with` target and subsequent method calls, then verify that the `reportUndefinedVariable` warning is removed without introducing warnings in the contrasting examples.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.