Skip to content

Commit

Permalink
add WithItemVar
Browse files Browse the repository at this point in the history
  • Loading branch information
danbi2990 committed Nov 9, 2023
1 parent 0e6f48a commit ab14d52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/ruff_linter/src/renamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl Renamer {
| BindingKind::Assignment
| BindingKind::BoundException
| BindingKind::LoopVar
| BindingKind::WithItemVar
| BindingKind::Global
| BindingKind::Nonlocal(_)
| BindingKind::ClassDefinition(_)
Expand Down
4 changes: 3 additions & 1 deletion crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub(crate) fn non_ascii_name(binding: &Binding, locator: &Locator) -> Option<Dia
BindingKind::Assignment => Kind::Assignment,
BindingKind::TypeParam => Kind::TypeParam,
BindingKind::LoopVar => Kind::LoopVar,
BindingKind::WithItemVar => Kind::WithItemVar,
BindingKind::Global => Kind::Global,
BindingKind::Nonlocal(_) => Kind::Nonlocal,
BindingKind::ClassDefinition(_) => Kind::ClassDefinition,
Expand Down Expand Up @@ -89,6 +90,7 @@ enum Kind {
Assignment,
TypeParam,
LoopVar,
WithItemVar,
Global,
Nonlocal,
ClassDefinition,
Expand All @@ -105,7 +107,7 @@ impl fmt::Display for Kind {
Kind::UnpackedAssignment => f.write_str("Variable"),
Kind::Assignment => f.write_str("Variable"),
Kind::TypeParam => f.write_str("Type parameter"),
Kind::LoopVar => f.write_str("Variable"),
Kind::LoopVar | Kind::WithItemVar => f.write_str("Variable"),
Kind::Global => f.write_str("Global"),
Kind::Nonlocal => f.write_str("Nonlocal"),
Kind::ClassDefinition => f.write_str("Class"),
Expand Down
7 changes: 7 additions & 0 deletions crates/ruff_python_semantic/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ pub enum BindingKind<'a> {
/// Stores the ID of the binding that was shadowed in the enclosing
/// scope, if any.
UnboundException(Option<BindingId>),

/// A binding for a with statement variable, like `x` in:
/// ```python
/// with open('foo.py') as x:
/// ...
/// ```
WithItemVar,
}

bitflags! {
Expand Down

0 comments on commit ab14d52

Please sign in to comment.