Skip to content

Commit 060a25d

Browse files
authored
Rename semantic model flag LITERAL to TYPING_LITERAL (#8997)
This PR renames the semantic model flag `LITERAL` to `TYPING_LITERAL` to better reflect its purpose. The main motivation behind this change is to avoid any confusion with the "literal" terminology used in the AST for literal nodes like string, bytes, numbers, etc.
1 parent f5d4676 commit 060a25d

File tree

2 files changed

+6
-6
lines changed
  • crates

2 files changed

+6
-6
lines changed

crates/ruff_linter/src/checkers/ast/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ where
816816
fn visit_expr(&mut self, expr: &'b Expr) {
817817
// Step 0: Pre-processing
818818
if !self.semantic.in_f_string()
819-
&& !self.semantic.in_literal()
819+
&& !self.semantic.in_typing_literal()
820820
&& !self.semantic.in_deferred_type_definition()
821821
&& self.semantic.in_type_definition()
822822
&& self.semantic.future_annotations()
@@ -1198,7 +1198,7 @@ where
11981198
) {
11991199
// Ex) Literal["Class"]
12001200
Some(typing::SubscriptKind::Literal) => {
1201-
self.semantic.flags |= SemanticModelFlags::LITERAL;
1201+
self.semantic.flags |= SemanticModelFlags::TYPING_LITERAL;
12021202

12031203
self.visit_expr(slice);
12041204
self.visit_expr_context(ctx);
@@ -1239,7 +1239,7 @@ where
12391239
}
12401240
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
12411241
if self.semantic.in_type_definition()
1242-
&& !self.semantic.in_literal()
1242+
&& !self.semantic.in_typing_literal()
12431243
&& !self.semantic.in_f_string()
12441244
{
12451245
self.deferred.string_type_definitions.push((

crates/ruff_python_semantic/src/model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,8 @@ impl<'a> SemanticModel<'a> {
13591359
}
13601360

13611361
/// Return `true` if the model is in a `typing::Literal` annotation.
1362-
pub const fn in_literal(&self) -> bool {
1363-
self.flags.intersects(SemanticModelFlags::LITERAL)
1362+
pub const fn in_typing_literal(&self) -> bool {
1363+
self.flags.intersects(SemanticModelFlags::TYPING_LITERAL)
13641364
}
13651365

13661366
/// Return `true` if the model is in a subscript expression.
@@ -1576,7 +1576,7 @@ bitflags! {
15761576
/// def f(x: Literal["A", "B", "C"]):
15771577
/// ...
15781578
/// ```
1579-
const LITERAL = 1 << 9;
1579+
const TYPING_LITERAL = 1 << 9;
15801580

15811581
/// The model is in a subscript expression.
15821582
///

0 commit comments

Comments
 (0)