ruff/crates
Charlie Marsh b3240dbfa2
Avoid propagating BindingKind::Global and BindingKind::Nonlocal (#5136)
## Summary

This PR fixes a small quirk in the semantic model. Typically, when we
see an import, like `import foo`, we create a `BindingKind::Importation`
for it. However, if `foo` has been declared as a `global`, then we
propagate the kind forward. So given:

```python
global foo

import foo
```

We'd create two bindings for `foo`, both with type `global`.

This was originally borrowed from Pyflakes, and it exists to help avoid
false-positives like:

```python
def f():
    global foo

    # Don't mark `foo` as "assigned but unused"! It's a global!
    foo = 1
```

This PR removes that behavior, and instead tracks "Does this binding
refer to a global?" as a flag. This is much cleaner, since it means we
don't "lose" the identity of various bindings.

As a very strange example of why this matters, consider:

```python
def foo():
    global Member

    from module import Member

    x: Member = 1
```

`Member` is only used in a typing context, so we should flag it and say
"move it to a `TYPE_CHECKING` block". However, when we go to analyze
`from module import Member`, it has `BindingKind::Global`. So we don't
even know that it's an import!
2023-06-16 11:06:59 -04:00
..
flake8_to_ruff Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff Avoid propagating BindingKind::Global and BindingKind::Nonlocal (#5136) 2023-06-16 11:06:59 -04:00
ruff_benchmark Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_cache Run rustfmt on nightly to clean up erroneous comments (#5106) 2023-06-15 00:19:05 +00:00
ruff_cli Remove FixMode::None (#5087) 2023-06-14 11:17:09 -04:00
ruff_dev Add roundtrip support for Jupyter notebook (#5028) 2023-06-12 23:27:45 +05:30
ruff_diagnostics Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_formatter Run rustfmt on nightly to clean up erroneous comments (#5106) 2023-06-15 00:19:05 +00:00
ruff_index Run rustfmt on nightly to clean up erroneous comments (#5106) 2023-06-15 00:19:05 +00:00
ruff_macros Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_python_ast Use matches! for insecure hash rule (#5141) 2023-06-16 04:18:32 +00:00
ruff_python_formatter Always use identifier ranges to store bindings (#5110) 2023-06-15 18:43:19 +00:00
ruff_python_semantic Avoid propagating BindingKind::Global and BindingKind::Nonlocal (#5136) 2023-06-16 11:06:59 -04:00
ruff_python_stdlib Avoid allocations in lowercase comparisons (#5137) 2023-06-16 08:57:43 -04:00
ruff_python_whitespace Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_rustpython Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_testing_macros Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_textwrap Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_wasm Add support for auto-fix in Jupyter notebooks (#4665) 2023-06-12 14:14:15 +00:00