|
1 | 1 | //! Analysis rules for the `typing` module.
|
2 | 2 |
|
3 |
| -use ruff_python_ast::helpers::{any_over_expr, is_const_false, map_subscript}; |
| 3 | +use ruff_python_ast::helpers::{any_over_expr, map_subscript}; |
4 | 4 | use ruff_python_ast::identifier::Identifier;
|
5 | 5 | use ruff_python_ast::name::QualifiedName;
|
6 | 6 | use ruff_python_ast::{
|
7 |
| - self as ast, Expr, ExprCall, ExprName, Int, Operator, ParameterWithDefault, Parameters, Stmt, |
| 7 | + self as ast, Expr, ExprCall, ExprName, Operator, ParameterWithDefault, Parameters, Stmt, |
8 | 8 | StmtAssign,
|
9 | 9 | };
|
10 | 10 | use ruff_python_stdlib::typing::{
|
@@ -391,44 +391,19 @@ pub fn is_mutable_expr(expr: &Expr, semantic: &SemanticModel) -> bool {
|
391 | 391 | pub fn is_type_checking_block(stmt: &ast::StmtIf, semantic: &SemanticModel) -> bool {
|
392 | 392 | let ast::StmtIf { test, .. } = stmt;
|
393 | 393 |
|
394 |
| - if semantic.use_new_type_checking_block_detection_semantics() { |
395 |
| - return match test.as_ref() { |
396 |
| - // As long as the symbol's name is "TYPE_CHECKING" we will treat it like `typing.TYPE_CHECKING` |
397 |
| - // for this specific check even if it's defined somewhere else, like the current module. |
398 |
| - // Ex) `if TYPE_CHECKING:` |
399 |
| - Expr::Name(ast::ExprName { id, .. }) => { |
400 |
| - id == "TYPE_CHECKING" |
| 394 | + match test.as_ref() { |
| 395 | + // As long as the symbol's name is "TYPE_CHECKING" we will treat it like `typing.TYPE_CHECKING` |
| 396 | + // for this specific check even if it's defined somewhere else, like the current module. |
| 397 | + // Ex) `if TYPE_CHECKING:` |
| 398 | + Expr::Name(ast::ExprName { id, .. }) => { |
| 399 | + id == "TYPE_CHECKING" |
401 | 400 | // Ex) `if TC:` with `from typing import TYPE_CHECKING as TC`
|
402 | 401 | || semantic.match_typing_expr(test, "TYPE_CHECKING")
|
403 |
| - } |
404 |
| - // Ex) `if typing.TYPE_CHECKING:` |
405 |
| - Expr::Attribute(ast::ExprAttribute { attr, .. }) => attr == "TYPE_CHECKING", |
406 |
| - _ => false, |
407 |
| - }; |
408 |
| - } |
409 |
| - |
410 |
| - // Ex) `if False:` |
411 |
| - if is_const_false(test) { |
412 |
| - return true; |
413 |
| - } |
414 |
| - |
415 |
| - // Ex) `if 0:` |
416 |
| - if matches!( |
417 |
| - test.as_ref(), |
418 |
| - Expr::NumberLiteral(ast::ExprNumberLiteral { |
419 |
| - value: ast::Number::Int(Int::ZERO), |
420 |
| - .. |
421 |
| - }) |
422 |
| - ) { |
423 |
| - return true; |
424 |
| - } |
425 |
| - |
426 |
| - // Ex) `if typing.TYPE_CHECKING:` |
427 |
| - if semantic.match_typing_expr(test, "TYPE_CHECKING") { |
428 |
| - return true; |
| 402 | + } |
| 403 | + // Ex) `if typing.TYPE_CHECKING:` |
| 404 | + Expr::Attribute(ast::ExprAttribute { attr, .. }) => attr == "TYPE_CHECKING", |
| 405 | + _ => false, |
429 | 406 | }
|
430 |
| - |
431 |
| - false |
432 | 407 | }
|
433 | 408 |
|
434 | 409 | /// Returns `true` if the [`ast::StmtIf`] is a version-checking block (e.g., `if sys.version_info >= ...:`).
|
|
0 commit comments