microsoft / microsoft/pyright

Detect illegal use of type annotation on `global` or `nonlocal` symbol

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

Description

The use of a type annotation on a variable with `global` or `nonlocal` binding results in a "syntax error" at runtime, but pyright does not detect or report this error.

```python
def func():
global x
x: str # Runtime error
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported example in Pyright and compare its result with Python's runtime syntax error for an annotation on a global or nonlocal symbol. Trace the analyzer entry point that handles global/nonlocal bindings and variable annotations; done means Pyright reports this invalid construct consistently.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.