Skip to content

Commit 8924766

Browse files
VeaaCCopilot
andcommitted
fix: add @overload to Engine.render_python_module for correct mypy typing
When archive_name is a str, the method returns tuple[ModuleType, Any]. When archive_name is None (default), it returns just ModuleType. Without overloads, mypy sees the union return type and rejects tuple unpacking at call sites (attr-defined: Module has no __iter__). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3dfcb60 commit 8924766

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • flatdata-generator/flatdata/generator

flatdata-generator/flatdata/generator/engine.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'''
55

66
import types
7-
from typing import Any
7+
from typing import Any, overload
88

99
from flatdata.generator.tree.builder import build_ast
1010
from flatdata.generator.tree.nodes.trivial.namespace import Namespace
@@ -65,6 +65,11 @@ def render(self, generator_name: str) -> str:
6565
output_content = generator.render(self.tree)
6666
return str(output_content)
6767

68+
@overload
69+
def render_python_module(self, module_name: str | None = None, *, archive_name: str, root_namespace: str | None = None) -> tuple[types.ModuleType, Any]: ...
70+
@overload
71+
def render_python_module(self, module_name: str | None = None, archive_name: None = None, root_namespace: str | None = None) -> types.ModuleType: ...
72+
6873
def render_python_module(self, module_name: str | None = None, archive_name: str | None = None, root_namespace: str | None = None) -> types.ModuleType | tuple[types.ModuleType, Any]:
6974
"""
7075
Render python module.

0 commit comments

Comments
 (0)