Skip to content

fix: pass mypy --strict in the small packages and read "false" as False in text - #785

Merged
Vincent Biret (baywet) merged 3 commits into
microsoft:mainfrom
HardMax71:fix/strict-typing-small-packages
Oct 14, 2026
Merged

Vincent Biret (baywet) merged 3 commits into
microsoft:mainfrom
HardMax71:fix/strict-typing-small-packages

Conversation

@HardMax71

Copy link
Copy Markdown
Contributor

Overview

Second item of the checklist in #722. It brings kiota_authentication_azure, kiota_bundle and the json, form, text and multipart serialization packages to zero errors under mypy --strict, and sets strict = true in their [tool.mypy] sections, so the existing CI mypy step keeps them there.

Most of it is missing return annotations and bare dicts. Bundle's two errors were calls to the untyped __new__ of ParseNodeFactoryRegistry and SerializationWriterFactoryRegistry, so those two get annotated in kiota_abstractions too.

Typing TextParseNode turned up a real bug. get_bool_value returned bool(self._text), so any non-empty text came back True, including a text/plain body of false, which is what TextSerializationWriter writes for False. It now compares the stripped, lowercased text to "true", the way FormParseNode does.

Related Issue

Part of #722, which stays open for the remaining items.

Notes

Nothing here should break callers. The azure options parameter goes from dict to dict[str, Any], which **options already required at runtime, and the registry constructors still accept and ignore any arguments.

The old test_get_bool_value passed the bool False into the text: str parameter, which is why the is False checks were there. The test now uses strings. TextParseNode("") also stops leaving _text unset, so its getters return None instead of raising AttributeError. The factory rejects empty content before that point anyway.

In JsonParseNode.get_collection_of_primitive_values, the inner func is annotated -> Any. It dispatches through a dict of converters, and mypy can't tie each converter back to T, so this only spells out the type it already had.

Typing the registry constructors also clears the five untyped calls in api_client_builder and two in httpx_request_adapter. With mypy 2.4.0, mypy --strict across the eight packages goes from 203 to 179 errors.

Testing Instructions

  • mypy <package> passes from each of the six package folders, and it's a strict run now through the config. It passes with --python-version 3.10 and --python-version 3.14 too.
  • mypy kiota_abstractions from packages/abstractions and mypy validation from tests/validation still pass.
  • yapf -dr, pylint --disable=W and pytest pass for the six packages and abstractions.
  • Without the text_parse_node.py change, pytest tests/unit/test_text_parse_node.py in packages/serialization/text fails on test_get_bool_value[false-False].

…se in text

Fill the remaining annotation gaps in kiota_authentication_azure, kiota_bundle and the json, form, text and multipart serialization packages, and set strict = true in their [tool.mypy] sections so CI keeps them at zero. Bundle's two errors were calls to the untyped __new__ of ParseNodeFactoryRegistry and SerializationWriterFactoryRegistry, so those get annotated in kiota_abstractions too.

TextParseNode.get_bool_value returned bool(text), so any non-empty text read as True, including a text/plain body of "false". It now compares the stripped, lowercased text to "true", like the form parse node does. Part of microsoft#722.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation is consistent and low risk, with only a non-blocking empty-input regression-test gap.

1 open finding
What changed in this PR

Adds strict mypy enforcement to six smaller packages, completes required annotations, and fixes text deserialization of false.

Changes:

  • Enables strict mypy checking across six packages.
  • Adds missing generic, return, registry, URL, and tracing annotations.
  • Corrects text boolean parsing and updates its regression test.
File Description
packages/​serialization/​text/​tests/​unit/​test_text_parse_node.py Tests textual boolean parsing.
packages/​serialization/​text/​pyproject.toml Enables strict mypy.
packages/​serialization/​text/​kiota_serialization_text/​text_parse_node.py Initializes empty text and parses booleans correctly.
packages/​serialization/​multipart/​pyproject.toml Enables strict mypy.
packages/​serialization/​multipart/​kiota_serialization_multipart/​multipart_serialization_writer.py Adds a return annotation.
packages/​serialization/​json/​pyproject.toml Enables strict mypy.
packages/​serialization/​json/​kiota_serialization_json/​json_serialization_writer.py Tightens writer and helper annotations.
packages/​serialization/​json/​kiota_serialization_json/​json_parse_node.py Annotates primitive conversion and removes an obsolete suppression.
packages/​serialization/​form/​pyproject.toml Enables strict mypy.
packages/​serialization/​form/​kiota_serialization_form/​form_serialization_writer.py Adds a return annotation.
packages/​bundle/​pyproject.toml Enables strict mypy.
packages/​authentication/​azure/​pyproject.toml Enables strict mypy.
packages/​authentication/​azure/​kiota_authentication_azure/​azure_identity_authentication_provider.py Types authentication options.
packages/​authentication/​azure/​kiota_authentication_azure/​azure_identity_access_token_provider.py Types options, parsed URLs, and spans.
packages/​abstractions/​kiota_abstractions/​serialization/​serialization_writer_factory_registry.py Types the singleton constructor.
packages/​abstractions/​kiota_abstractions/​serialization/​parse_node_factory_registry.py Types the singleton constructor.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/serialization/text/tests/unit/test_text_parse_node.py Outdated
@baywet

Copy link
Copy Markdown
Member

Max Azatian (@HardMax71) would you mind addressing copilot's feedback please?

Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@HardMax71

Copy link
Copy Markdown
Contributor Author

Vincent Biret (@baywet) addressed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The annotation changes are narrow, the parsing fix has regression coverage, and no blocking issues remain.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

Copilot AI balanced review requested due to automatic review settings October 14, 2026 17:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@baywet
Vincent Biret (baywet) merged commit 70a6190 into microsoft:main Oct 14, 2026
104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants