Skip to content

Commit 5629526

Browse files
committed
Fix type annotations in inference codegen
1 parent 5ee19a9 commit 5629526

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

utils/generate_inference_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ def fix_inference_classes(content: str, module_name: str) -> str:
294294
return content
295295

296296

297+
def fix_legacy_annotation(content: str) -> str:
298+
"""Fix legacy type annotations (e.g., `List` -> `list`)."""
299+
lines = content.split("\n")
300+
for i, line in enumerate(lines):
301+
# Skip import lines
302+
if line.strip().startswith(("from ", "import ")):
303+
continue
304+
for key in ["List", "Dict"]:
305+
line = re.sub(r"\b" + key + r"\b", key.lower(), line)
306+
lines[i] = line
307+
return "\n".join(lines)
308+
309+
297310
def create_init_py(dataclasses: dict[str, list[str]]):
298311
"""Create __init__.py file with all dataclasses."""
299312
content = INIT_PY_HEADER
@@ -344,6 +357,7 @@ def check_inference_types(update: bool) -> NoReturn:
344357
content = file.read_text()
345358
content = _clean_deprecated_fields(content)
346359
fixed_content = fix_inference_classes(content, module_name=file.stem)
360+
fixed_content = fix_legacy_annotation(fixed_content)
347361
formatted_content = format_source_code(fixed_content)
348362
dataclasses[file.stem] = _list_dataclasses(formatted_content)
349363
aliases[file.stem] = _list_type_aliases(formatted_content)

0 commit comments

Comments
 (0)