Skip to content

Commit

Permalink
More comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jan 18, 2024
1 parent d2bfd3d commit 9a9af40
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,35 @@ pub(crate) fn unused_private_typed_dict(
fn extract_typeddict_name<'a>(stmt: &'a Stmt, semantic: &SemanticModel) -> Option<&'a str> {
let is_typeddict = |expr: &ast::Expr| semantic.match_typing_expr(expr, "TypedDict");
match stmt {
// E.g. return `Some("Foo")` for the first one of these classes,
// and `Some("Bar")` for the second:
//
// ```python
// import typing
// from typing import TypedDict
//
// class Foo(TypedDict):
// x: int
//
// T = typing.TypeVar("T")
//
// class Bar(typing.TypedDict, typing.Generic[T]):
// y: T
// ```
Stmt::ClassDef(class_def @ ast::StmtClassDef { name, .. }) => {
if class_def.bases().iter().any(is_typeddict) {
Some(name)
} else {
None
}
}
// E.g. return `Some("Baz")` for this assignment,
// which is an accepted alternative way of creating a TypedDict type:
//
// ```python
// import typing
// Baz = typing.TypedDict("Baz", {"z": bytes})
// ```
Stmt::Assign(ast::StmtAssign { targets, value, .. }) => {
let [target] = targets.as_slice() else {
return None;
Expand Down

0 comments on commit 9a9af40

Please sign in to comment.