Skip to content

Commit b57aa5c

Browse files
committed
updates comment and removes redundant check.
1 parent da97d1d commit b57aa5c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

scripts/microgenerator/generate.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import ast
2626
import os
2727
from collections import defaultdict
28-
from typing import List, Dict, Any, Iterator
28+
from typing import List, Dict, Any
2929

3030
from . import utils
3131

@@ -65,7 +65,7 @@ def _get_type_str(self, node: ast.AST | None) -> str | None:
6565
if isinstance(curr, ast.Name):
6666
parts.append(curr.id)
6767
return ".".join(reversed(parts))
68-
# Handles subscripted types like 'list[str]', 'Optional[...]'
68+
# Handles subscripted types like 'list[str]', 'Optional[...]'
6969
if isinstance(node, ast.Subscript):
7070
value_str = self._get_type_str(node.value)
7171
slice_str = self._get_type_str(node.slice)
@@ -191,16 +191,20 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
191191
self._is_in_method = False
192192

193193
def _add_attribute(self, attr_name: str, attr_type: str | None = None):
194-
"""Adds a unique attribute to the current class context."""
195-
if self._current_class_info:
196-
# Create a list of attribute names for easy lookup
197-
attr_names = [
198-
attr.get("name") for attr in self._current_class_info["attributes"]
199-
]
200-
if attr_name not in attr_names:
201-
self._current_class_info["attributes"].append(
202-
{"name": attr_name, "type": attr_type}
203-
)
194+
"""Adds a unique attribute to the current class context.
195+
196+
Assumes self._current_class_info is not None, as this method
197+
is only called from within visit_Assign and visit_AnnAssign
198+
after checking for an active class context.
199+
"""
200+
# Create a list of attribute names for easy lookup
201+
attr_names = [
202+
attr.get("name") for attr in self._current_class_info["attributes"]
203+
]
204+
if attr_name not in attr_names:
205+
self._current_class_info["attributes"].append(
206+
{"name": attr_name, "type": attr_type}
207+
)
204208

205209
def visit_Assign(self, node: ast.Assign) -> None:
206210
"""Handles attribute assignments: `x = ...` and `self.x = ...`."""

0 commit comments

Comments
 (0)