scoping icon indicating copy to clipboard operation
scoping copied to clipboard

Request: Improve type hinting so that variables from inside a `scoping` block have an access warning outside the block

Open DeflateAwning opened this issue 10 months ago • 0 comments

In the following code snippet, I wish Pyright (the Python static type checking/static analysis tool) could give a static analysis warning here.

Any idea if that's possible?

    with scoping():
        y = 2

    print(f"Outside the block, y={y}")  # <- I wish Pyright could catch this error before runtime.

In comparison, the alternative less-readable del-based code, does indeed cause Pyright to notify about the use of an unbound variable:


y = 2
del y

print(f"After the block, y={y}")  # <- I wish Pyright could catch this error before runtime.

DeflateAwning avatar Mar 06 '25 01:03 DeflateAwning