microsoft / microsoft/pyright

reportOptionalMemberAccess after raise ValueError

Open
#11,089 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug question
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**
After checking variable for none value with valueerror raise pylance says about possible none value

**Code or Screenshots**
```python
# Tag is html tag of bs4
# a is value Optional[Tag] (Tag | None)
if a is None:
raise ValueError("...")
b = a.text # here error, pylance says that .text is not attr of None
```

**VS Code extension or command-line**
vscode; pylance 2025.16.0

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

Start with the provided minimal Python example in the Pylance VS Code extension and reproduce the diagnostic with pylance 2025.16.0. Investigate how the checker handles narrowing after raising ValueError; done means the diagnostic is no longer reported for a.text after the None check, with regression coverage for this example.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.