Skip to content

Commit

Permalink
[pep8-naming] Avoid N806 errors for type alias statements (#8785)
Browse files Browse the repository at this point in the history
Allow, e.g.:

```python
def func():
    type MyInt = int
```

(We already allowed `MyInt: TypeAlias = int`.)

Closes #8773.
  • Loading branch information
charliermarsh authored Nov 20, 2023
1 parent 653e51a commit 10d937c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def assign():

IntOrStr: TypeAlias = int | str

type MyInt = int


def aug_assign(rank, world_size):
global CURRENT_PORT
Expand Down
11 changes: 7 additions & 4 deletions crates/ruff_linter/src/rules/pep8_naming/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ pub(super) fn is_type_var_assignment(stmt: &Stmt, semantic: &SemanticModel) -> b

/// Returns `true` if the statement is an assignment to a `TypeAlias`.
pub(super) fn is_type_alias_assignment(stmt: &Stmt, semantic: &SemanticModel) -> bool {
let Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. }) = stmt else {
return false;
};
semantic.match_typing_expr(annotation, "TypeAlias")
match stmt {
Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. }) => {
semantic.match_typing_expr(annotation, "TypeAlias")
}
Stmt::TypeAlias(_) => true,
_ => false,
}
}

pub(super) fn is_typed_dict_class(arguments: Option<&Arguments>, semantic: &SemanticModel) -> bool {
Expand Down

0 comments on commit 10d937c

Please sign in to comment.