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