Skip to content

Commit fc3825e

Browse files
committed
[refactor] Process when Subscript only
1 parent 99f4d69 commit fc3825e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/kotoha/core.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ def is_annotated(annotation: ast.expr | None) -> TypeGuard[ast.expr]:
4646

4747
def visit_arg(self, node: ast.arg) -> None:
4848
if self.is_annotated(node.annotation):
49-
annotation = node.annotation
50-
if (
51-
hasattr(annotation, "value")
52-
and annotation.value.id in self._concrete_type_hint_error_codes
53-
):
54-
self.errors.append(
55-
(
56-
node.lineno,
57-
node.col_offset,
58-
self._concrete_type_hint_error_codes[
59-
annotation.value.id
60-
],
49+
# node.annotations is ast.Name, ast.Subscript or ast.Attribute
50+
if isinstance(node.annotation, ast.Subscript):
51+
value_node = node.annotation.value
52+
assert isinstance(value_node, ast.Name)
53+
if value_node.id in self._concrete_type_hint_error_codes:
54+
self.errors.append(
55+
(
56+
node.lineno,
57+
node.col_offset,
58+
self._concrete_type_hint_error_codes[
59+
value_node.id
60+
],
61+
)
6162
)
62-
)
6363
self.generic_visit(node)
6464

6565

0 commit comments

Comments
 (0)