mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00
![]() ## Summary This PR adds a new `LiteralExpressionRef` which wraps all of the literal expression nodes in a single enum. This allows for a narrow type when working exclusively with a literal node. Additionally, it also implements a `Expr::as_literal_expr` method to return the new enum if the expression is indeed a literal one. A few rules have been updated to account for the new enum: 1. `redundant_literal_union` 2. `if_else_block_instead_of_dict_lookup` 3. `magic_value_comparison` To account for the change in (2), a new `ComparableLiteral` has been added which can be constructed from the new enum (`ComparableLiteral::from(<LiteralExpressionRef>)`). ### Open Questions 1. The new `ComparableLiteral` can be exclusively used via the `LiteralExpressionRef` enum. Should we remove all of the literal variants from `ComparableExpr` and instead have a single `ComparableExpr::Literal(ComparableLiteral)` variant instead? ## Test Plan `cargo test` |
||
---|---|---|
.. | ||
visitor | ||
all.rs | ||
call_path.rs | ||
comparable.rs | ||
docstrings.rs | ||
expression.rs | ||
hashable.rs | ||
helpers.rs | ||
identifier.rs | ||
imports.rs | ||
int.rs | ||
lib.rs | ||
node.rs | ||
nodes.rs | ||
parenthesize.rs | ||
relocate.rs | ||
statement_visitor.rs | ||
stmt_if.rs | ||
str.rs | ||
traversal.rs | ||
types.rs | ||
visitor.rs | ||
whitespace.rs |