Skip to content

fix(abstractions): default the type params of RequestAdapter and ParsableFactory - #787

Open
Max Azatian (HardMax71) wants to merge 1 commit into
microsoft:mainfrom
HardMax71:fix/typevar-defaults-for-bare-generics
Open

Max Azatian (HardMax71) wants to merge 1 commit into
microsoft:mainfrom
HardMax71:fix/typevar-defaults-for-bare-generics

Conversation

@HardMax71

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

Copy link
Copy Markdown
Contributor

Overview

Generated clients use RequestAdapter and ParsableFactory without type arguments. Every request builder takes request_adapter: RequestAdapter, and every error map is a dict[str, type[ParsableFactory]]. Under mypy --strict each of those is a "Missing type arguments" error wherever the generated code is checked, which is the usual setup when kiota generates a client into a project. They're all 141 strict errors left in the validation client, and msgraph-sdk 1.64.0 has about 26,500 such annotations.

This gives both type parameters a default (PEP 696) at the top of their range, so the bare names stay checked and strict checkers accept them without any generator change or regeneration:

  • ParsableFactory's U_co defaults to its bound, Parsable. It's covariant, so every ParsableFactory[X] still fits a bare ParsableFactory.
  • RequestAdapter's type parameter only appears as the return type of convert_to_native_async, so it becomes covariant and defaults to object, which every adapter's native request type fits.

TypeVar only takes a default in the stdlib from 3.13, so it comes from typing_extensions, which becomes a declared dependency of abstractions. It was already installed through opentelemetry-api.

tests/validation gets strict = true, so the existing validation job fails if generated code picks up a strict error again.

Related Issue

Part of #722, added there as its own item.

Notes

pylint wants the _co suffix on a covariant TypeVar, so RequestType is renamed to RequestType_co. Nothing in kiota-python, msgraph-sdk 1.64.0 or msgraph-core 1.5.2 imports it, and GitHub code search finds no importers either.

HttpxRequestAdapter.send_collection_async took a bare ParsableFactory, which only type-checked because the bare name meant ParsableFactory[Any]. It now declares ParsableFactory[ModelType], like the method it overrides.

As a downstream check, msgraph-sdk-python-core's CI step mypy src (mypy 1.17.1) still passes against this branch, and its strict run goes from 70 to 60 errors.

The floor is typing-extensions 4.4.0, the release that added default. The abstractions tests pass on Python 3.10 with exactly that version.

Since abstractions and http use the bare names themselves, mypy --strict also goes from 63 to 51 errors in abstractions and from 127 to 117 in http (mypy 2.4.0). It merges cleanly with #785.

Testing Instructions

  • From tests/validation, mypy validation (now strict) passes, also with --python-version 3.10 and 3.14. On main the strict run reports 141 errors.
  • The normal mypy run passes for all eight packages.
  • yapf -dr, isort, pylint --disable=W and pytest pass for abstractions, and yapf, isort and pylint pass for http.

@HardMax71

Copy link
Copy Markdown
Contributor Author

hmm, default=any = no limits at all. I'll convert this PR to draft and reopen later

@HardMax71
Max Azatian (HardMax71) marked this pull request as draft October 10, 2026 15:27
…ableFactory

Generated clients annotate request_adapter: RequestAdapter and dict[str, type[ParsableFactory]] without type arguments, which mypy --strict reports wherever the generated code is checked. That's all 141 strict errors in tests/validation, and msgraph-sdk 1.64.0 has about 26,500 such annotations.

Give both type parameters a PEP 696 default at the top of their range. ParsableFactory's U_co defaults to its bound, Parsable, and since it's covariant every ParsableFactory[X] still fits the bare name. RequestAdapter's type parameter is only returned by convert_to_native_async, so it becomes covariant and defaults to object; pylint wants the _co suffix, so it's renamed to RequestType_co. HttpxRequestAdapter.send_collection_async now declares ParsableFactory[ModelType] like the method it overrides, since the bare name no longer means Any.

TypeVar only takes a default in the stdlib from 3.13, so it comes from typing_extensions, now a declared dependency of abstractions (it was already installed through opentelemetry-api). tests/validation runs with strict = true so CI catches a regression. Part of microsoft#722.
@HardMax71
Max Azatian (HardMax71) force-pushed the fix/typevar-defaults-for-bare-generics branch from 8a575ec to ea9b41c Compare October 10, 2026 15:31
@HardMax71 Max Azatian (HardMax71) changed the title fix(abstractions): default RequestAdapter and ParsableFactory type params to Any fix(abstractions): default the type params of RequestAdapter and ParsableFactory Oct 10, 2026
@sonarqubecloud

Copy link
Copy Markdown

@HardMax71

Max Azatian (HardMax71) commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Rename from RequestType to RequestType_co is needed solely cause of pylint: it doesn't allow covariants without "_co" suffix. mypy doesn't care.

Ready for review btw

@HardMax71
Max Azatian (HardMax71) marked this pull request as ready for review October 10, 2026 15:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant