Skip to content

fix(abstractions): pass mypy --strict in store and fix the backing store bugs it shows - #800

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

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

Conversation

@HardMax71

@HardMax71 Max Azatian (HardMax71) commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fourth item in #722. kiota_abstractions.store now passes mypy --strict, and errors in kiota_abstractions go from 42 to 20.

BackingStore and InMemoryBackingStore now default their type parameter to object, like RequestAdapter in #787. So the backing_store: BackingStore = field(...) line in generated models passes strict without regenerating. On main it has two errors.

Adding types showed three bugs:

  • BackingStoreFactorySingleton was never a singleton. hasattr(cls, "__instance") looks for a name that never exists, since Python renames __instance inside the class. So every call made a new instance, and a call with None reset the factory. Generated models make that call at import, so a factory passed to enable_backing_store never stuck. Now there's one instance. None keeps the factory and a factory replaces it, like Instance in kiota-dotnet.
  • InMemoryBackingStore.get unwrapped any tuple, so a stored (1, 2) came back as 1. A list's size is now kept apart from the value, so get returns what was set.
  • Subscribers got internal entries like (False, "a"). They now get the old and new values, as subscribe says.

Related Issue

Part of #722.

Notes

The singleton and subscriber fixes change runtime behavior. Models imported before enable_backing_store keep their old factory, since generated code binds it at import.

Two smaller store bugs are fixed separately in #802: list items get one more subscription each time the list is set, and the is_initialization_completed setter writes back a stale list size.

Testing Instructions

  • mypy --strict kiota_abstractions in packages/abstractions shows nothing under store/, also with --python-version 3.10.
  • mypy kiota_abstractions, mypy validation in tests/validation, yapf -dr kiota_abstractions and pytest pass.
  • The three new tests fail without the source changes.

…ore bugs it shows

Annotate the rest of kiota_abstractions.store and default the BackingStore and InMemoryBackingStore type parameters to object, like RequestAdapter and ParsableFactory, so generated models that declare a bare `backing_store: BackingStore` still pass mypy --strict.

BackingStoreFactorySingleton was never a singleton. `hasattr(cls, "__instance")` checks the unmangled name, so every call built a new instance and assigned the factory over the `backing_store_factory` property on the class, and a call with None put back a fresh InMemoryBackingStoreFactory. Generated models call it with None at import, so a factory passed to enable_backing_store never stuck. It now keeps one instance, None keeps the current factory, and a factory replaces it.

InMemoryBackingStore stored lists as a (list, size) tuple and get() unwrapped any tuple, so a stored tuple such as (1, 2) came back as 1. Entries now keep the value and the list's size side by side, so get() returns what was set. enumerate_() still returns the (list, size) pair for lists. Subscribers now get the previous and new values, as subscribe documents, instead of the internal entries. Part of #722.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:08
@HardMax71
Max Azatian (HardMax71) requested a review from a team as a code owner October 14, 2026 19:08

This comment was marked as off-topic.

@HardMax71

Max Azatian (HardMax71) commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
Check failure: Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-abstractions->python&issues=AaE70WndYliNO_INcnKD&open=AaE70WndYliNO_INcnKD&pullRequest=800

Wonder why I see it in PR diff, and in CI SonarCloud is green.. Anyways, it is outside of this PR scope, so ignoring it

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 scoped typing changes and runtime fixes have regression coverage and no identified blocking issues.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:23

This comment was marked as off-topic.

@sonarqubecloud

Copy link
Copy Markdown

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

Static review found no blocking issues in the focused typing changes, runtime fixes, or regression tests; tests were not executed.

0 open findings

🧠 Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Oct 15, 2026
@baywet
Vincent Biret (baywet) merged commit 213fe0a into microsoft:main Oct 15, 2026
63 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants