ruff
f22c8ab8 - [red-knot] add maybe-undefined lint rule (#12414)

Comment changes are shownComment changes are hidden
Commit
347 days ago
[red-knot] add maybe-undefined lint rule (#12414) 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`.
Author
Parents
  • File
    Cargo.lock
  • crates
    • red_knot/src
      • File
        db.rs
      • File
        lint.rs
    • red_knot_python_semantic
      • File
        Cargo.toml
      • src
        • File
          db.rs
        • File
          types.rs
        • types
          • File
            infer.rs
    • ruff_db
      • File
        Cargo.toml
      • src/system
        • File
          test.rs