Add type annotations and mypy CI to flatdata-py and flatdata-generator#262
Open
VeaaC wants to merge 12 commits intoheremaps:masterfrom
Open
Add type annotations and mypy CI to flatdata-py and flatdata-generator#262VeaaC wants to merge 12 commits intoheremaps:masterfrom
VeaaC wants to merge 12 commits intoheremaps:masterfrom
Conversation
68dedef to
76e1c61
Compare
Signed-off-by: Christian Vetter <christian.vetter@here.com>
Signed-off-by: Christian Vetter <christian.vetter@here.com>
Signed-off-by: Christian Vetter <christian.vetter@here.com>
Signed-off-by: Christian Vetter <christian.vetter@here.com>
Signed-off-by: Christian Vetter <christian.vetter@here.com>
Signed-off-by: Christian Vetter <christian.vetter@here.com>
…ping 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> Signed-off-by: Christian Vetter <christian.vetter@here.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds type annotations to all source functions/methods in both Python projects and
enforces them via mypy in CI.
What changed
Type annotations: All 415 functions across 62 source files are annotated.
This includes closure/nested functions (Jinja2 filters, data access readers,
validation helpers) and all properties.
mypy configuration (both
pyproject.toml): 9 strictness flags enabled —disallow_untyped_defs,check_untyped_defs,disallow_any_generics,warn_return_any,warn_unused_configs,warn_redundant_casts,warn_unused_ignores,no_implicit_optional,strict_equality. Namespacepackage settings for the shared
flatdata/namespace.CI: mypy steps added to
generator.ymlandpy.yml, running after tests.PEP 561:
py.typedmarkers inflatdata/lib/andflatdata/generator/.Notable type improvements
Node.iterate(),children_like(),first_parent_like()made generic via@overload/TypeVar— eliminates ~20 potential# type: ignorecommentsthroughout the tree and builder code.
NamedTupleclasses(
BfsAttr,DfsAttr)..docproperties typed asstr(wereAny).referenced_structurestypedas
list[BuiltinStructureReference | StructureReference](waslist[Any])._raisecorrectly typed asNoReturn.enumeration.py:_bits_required).Remaining
type: ignore(22 total)All have specific error codes and justification comments. The majority (15) are
attr-definedonReference.node— the node accessor returnsNodebut callersaccess subclass attributes. Fixing this properly requires a
Referencetypehierarchy refactor. The rest are standard mypy limitations (property narrowing,
ABC isinstance, set.add idiom,
__repr__override).Not done
strict = trueevaluated, not adopted — adds ~100 errors from cross-packageno-untyped-calland missing__all__exports. Cost exceeds benefit.ReadableBufferProtocol fordata/memparameters — blocked by Python 3.10support (
collections.abc.Bufferrequires 3.12).