MCPcopy Create free account
hub / github.com/astral-sh/ruff / debug_shadowing

Method debug_shadowing

crates/ruff_python_parser/src/semantic_errors.rs:605–688  ·  view source on GitHub ↗

Check for [`SemanticSyntaxErrorKind::WriteToDebug`] in `stmt`.

(stmt: &ast::Stmt, ctx: &Ctx)

Source from the content-addressed store, hash-verified

603
604 /// Check for [`SemanticSyntaxErrorKind::WriteToDebug`] in `stmt`.
605 fn debug_shadowing<Ctx: SemanticSyntaxContext>(stmt: &ast::Stmt, ctx: &Ctx) {
606 match stmt {
607 Stmt::FunctionDef(ast::StmtFunctionDef {
608 name,
609 type_params,
610 parameters,
611 ..
612 }) => {
613 // test_err debug_shadow_function
614 // def __debug__(): ... # function name
615 // def f[__debug__](): ... # type parameter name
616 // def f(__debug__): ... # parameter name
617 // lambda __debug__: 0 # lambda parameter name
618 Self::check_identifier(name, ctx);
619 if let Some(type_params) = type_params {
620 for type_param in type_params.iter() {
621 Self::check_identifier(type_param.name(), ctx);
622 }
623 }
624 for parameter in parameters {
625 Self::check_identifier(parameter.name(), ctx);
626 }
627 }
628 Stmt::ClassDef(ast::StmtClassDef {
629 name, type_params, ..
630 }) => {
631 // test_err debug_shadow_class
632 // class __debug__: ... # class name
633 // class C[__debug__]: ... # type parameter name
634 Self::check_identifier(name, ctx);
635 if let Some(type_params) = type_params {
636 for type_param in type_params.iter() {
637 Self::check_identifier(type_param.name(), ctx);
638 }
639 }
640 }
641 Stmt::TypeAlias(ast::StmtTypeAlias {
642 type_params: Some(type_params),
643 ..
644 }) => {
645 // test_err debug_shadow_type_alias
646 // type __debug__ = list[int] # visited as an Expr but still flagged
647 // type Debug[__debug__] = str
648 for type_param in type_params.iter() {
649 Self::check_identifier(type_param.name(), ctx);
650 }
651 }
652 Stmt::Import(ast::StmtImport { names, .. })
653 | Stmt::ImportFrom(ast::StmtImportFrom { names, .. }) => {
654 // test_err debug_shadow_import
655 // import __debug__
656 // import debug as __debug__
657 // from x import __debug__
658 // from x import debug as __debug__
659
660 // test_ok debug_rename_import
661 // import __debug__ as debug
662 // from __debug__ import Some

Callers

nothing calls this directly

Calls 2

iterMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected