"possibly unbound" error when redefining builtin in try-except
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
After redefining a builtin with a try-except, using the builtin in a function results in a "possibly unbound" error.
Maybe similar to https://github.com/microsoft/pyright/issues/4074?
**Code or Screenshots**
```python
try:
from rich import print
except ModuleNotFoundError:
pass
def foo() -> None:
print(1, 2, 3)
```
or
```python
import sys
if sys.stdout.isatty():
try:
from rich import print
except ModuleNotFoundError:
pass
def foo() -> None:
print(1, 2, 3)
```
Using `rich~=14.2`
**VS Code extension or command-line**
pyright 1.1.406 on the command-line
Contributor guide
Research direction
Start by running the two Python reproductions with pyright 1.1.406 and inspect how the analyzer handles the try-except import that redefines print. Trace the possibly-unbound diagnostic for foo, then confirm the diagnostic is no longer reported while genuine unbound cases remain detected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100