Skip to content

Fix all mypy static typing errors#27

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-static-typing-errors
Draft

Fix all mypy static typing errors#27
Copilot wants to merge 3 commits intomainfrom
copilot/fix-static-typing-errors

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 9, 2026

hatch run types:check reported 24 errors across 6 files. This resolves all of them.

pyproject.toml

  • Add [[tool.mypy.overrides]] to ignore missing linkml_runtime.* stubs (no py.typed marker upstream)

src/pydantic2linkml/tools.py

  • Cast strip_function_schema to match Callable[[CoreSchema], CoreSchema] dict value type (contravariance mismatch with AnyFunctionSchema parameter)
  • Add @overload signatures to bucketize() so return type correctly reflects whether value_func is provided:
@overload
def bucketize(items: Iterable[T], key_func: Callable[[T], K]) -> defaultdict[K, list[T]]: ...

@overload
def bucketize(items: Iterable[T], key_func: Callable[[T], K], value_func: Callable[[T], V]) -> defaultdict[K, list[V]]: ...

src/pydantic2linkml/gen_linkml.py

  • Replace union-typed to_sorted_lst helper with explicitly typed model_lst: list[type[BaseModel]] and enum_lst: list[type[Enum]] — fixes 3 downstream errors (dict-key, arg-type, union-attr)
  • type: ignore[attr-defined] for _typing_extra.all_literal_values (renamed to literal_values in Pydantic 2.10)
  • type: ignore[typeddict-item] for schema["schema"] access guarded by mode != "plain" (mypy can't narrow union of TypedDicts via string comparison)

Tests

  • type: ignore[assignment] on intentional incompatible override in test_tools.py
  • Replace walrus operator := in @pytest.mark.parametrize tuples with explicit literals (mypy doesn't track assignment expressions in decorator args)
Original prompt

This section details on the original issue you should resolve

<issue_title>Fix static typing errors</issue_title>
<issue_description>Currently, running static type checking via hatch run types:check 2>&1 produces the following output.

`hatch run types:check 2>&1` output
src/pydantic2linkml/tools.py:15: error: Skipping analyzing "linkml_runtime.linkml_model": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/pydantic2linkml/tools.py:16: error: Skipping analyzing "linkml_runtime.utils.formatutils": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/pydantic2linkml/tools.py:156: error: Dict entry 0 has incompatible type "str": "Callable[[AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema], Mapping[str, Any]]"; expected "str": "Callable[[Mapping[str, Any]], Mapping[str, Any]]"  [dict-item]
src/pydantic2linkml/tools.py:157: error: Dict entry 1 has incompatible type "str": "Callable[[AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema], Mapping[str, Any]]"; expected "str": "Callable[[Mapping[str, Any]], Mapping[str, Any]]"  [dict-item]
src/pydantic2linkml/tools.py:158: error: Dict entry 2 has incompatible type "str": "Callable[[AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema], Mapping[str, Any]]"; expected "str": "Callable[[Mapping[str, Any]], Mapping[str, Any]]"  [dict-item]
src/pydantic2linkml/tools.py:159: error: Dict entry 3 has incompatible type "str": "Callable[[AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema], Mapping[str, Any]]"; expected "str": "Callable[[Mapping[str, Any]], Mapping[str, Any]]"  [dict-item]
src/pydantic2linkml/tools.py:308: error: Argument 1 to "append" of "list" has incompatible type "T | V"; expected "T"  [arg-type]
src/pydantic2linkml/tools.py:309: error: Incompatible return value type (got "defaultdict[K, list[T]]", expected "defaultdict[K, list[V]]")  [return-value]
src/pydantic2linkml/gen_linkml.py:14: error: Skipping analyzing "linkml_runtime.linkml_model": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/pydantic2linkml/gen_linkml.py:21: error: Skipping analyzing "linkml_runtime.linkml_model.meta": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/pydantic2linkml/gen_linkml.py:22: error: Skipping analyzing "linkml_runtime.utils.schema_builder": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/pydantic2linkml/gen_linkml.py:62: error: Module has no attribute "all_literal_values"  [attr-defined]
src/pydantic2linkml/gen_linkml.py:121: error: Key expression in dictionary comprehension has incompatible type "type[Enum] | type[BaseModel]"; expected type "type[BaseModel]"  [misc]
src/pydantic2linkml/gen_linkml.py:121: error: Argument 1 to "get_locally_defined_fields" has incompatible type "type[Enum] | type[BaseModel]"; expected "type[BaseModel]"  [arg-type]
src/pydantic2linkml/gen_linkml.py:158: error: Item "ModelMetaclass" of "type[Enum] | type[BaseModel]" has no attribute "__iter__" (not iterable)  [union-attr]
src/pydantic2linkml/gen_linkml.py:965: error: TypedDict "PlainValidatorFunctionSchema" has no key "schema"  [typeddict-item]
src/pydantic2linkml/cli/__init__.py:6: error: Skipping analyzing "linkml_runtime.dumpers": module is installed, but missing library stubs or py.typed marker  [import-untyped]
src/pydantic2linkml/cli/__init__.py:6: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
tests/test_tools.py:10: error: Skipping analyzing "linkml_runtime.linkml_model": module is installed, but missing library stubs or py.typed marker  [import-untyped]
tests/test_tools.py:83: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_tools.py:84: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_tools.py:85: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_tools.py:137: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_tools.py:138: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_tools.py:155: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_tools.py:156: note: By default the bodies of untyped functions are not check...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dandi/pydantic2linkml#26

<!-- START COPILOT CODING AGENT TIPS -->
---

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security)

Copilot AI and others added 2 commits March 9, 2026 18:26
- Add mypy override to ignore missing linkml_runtime type stubs
- Cast strip_function_schema for UNNEEDED_WRAPPING_SCHEMA_TYPE_TO_STRIP_FUNC dict
- Add @overload signatures for bucketize() to fix return type
- Add type: ignore for pydantic internal attr access (all_literal_values)
- Properly type model_lst and enum_lst in LinkmlGenerator.__init__
- Add type: ignore for PlainValidatorFunctionSchema missing 'schema' key
- Add type: ignore for intentional incompatible override in test
- Replace walrus operator usage in parametrize with explicit values

Co-authored-by: candleindark <12135617+candleindark@users.noreply.github.com>
Co-authored-by: candleindark <12135617+candleindark@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix static typing errors in tools.py Fix all mypy static typing errors Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants