mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:50:38 +00:00
![]() Add a lint rule to detect if a name is definitely or possibly undefined at a given usage. If I create the file `undef/main.py` with contents: ```python x = int def foo(): z return x if flag: y = x y ``` And then run `cargo run --bin red_knot -- --current-directory ../ruff-examples/undef`, I get the output: ``` Name 'z' used when not defined. Name 'flag' used when not defined. Name 'y' used when possibly not defined. ``` If I modify the file to add `y = 0` at the top, red-knot re-checks it and I get the new output: ``` Name 'z' used when not defined. Name 'flag' used when not defined. ``` Note that `int` is not flagged, since it's a builtin, and `return x` in the function scope is not flagged, since it refers to the global `x`. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |