Repository navigation
fix(abstractions): default the type params of RequestAdapter and ParsableFactory - #787
Open
Max Azatian (HardMax71) wants to merge 1 commit into
Open
Max Azatian (HardMax71) wants to merge 1 commit into
Max Azatian (HardMax71) wants to merge 1 commit into
Conversation
1 of 11 tasks
Contributor
Author
|
hmm, default=any = no limits at all. I'll convert this PR to draft and reopen later |
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.
Max Azatian (HardMax71)
force-pushed
the
fix/typevar-defaults-for-bare-generics
branch
from
October 10, 2026 15:31
8a575ec to
ea9b41c
Compare
|
Contributor
Author
|
Rename from Ready for review btw |
Max Azatian (HardMax71)
marked this pull request as ready for review
October 10, 2026 15:38
This branch has not been deployed
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.



Overview
Generated clients use
RequestAdapterandParsableFactorywithout type arguments. Every request builder takesrequest_adapter: RequestAdapter, and every error map is adict[str, type[ParsableFactory]]. Undermypy --stricteach 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'sU_codefaults to its bound,Parsable. It's covariant, so everyParsableFactory[X]still fits a bareParsableFactory.RequestAdapter's type parameter only appears as the return type ofconvert_to_native_async, so it becomes covariant and defaults toobject, which every adapter's native request type fits.TypeVaronly takes a default in the stdlib from 3.13, so it comes fromtyping_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
_cosuffix on a covariant TypeVar, soRequestTypeis renamed toRequestType_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_asynctook a bareParsableFactory, which only type-checked because the bare name meantParsableFactory[Any]. It now declaresParsableFactory[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 --strictalso 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
mypy validation(now strict) passes, also with--python-version 3.10and3.14. On main the strict run reports 141 errors.mypyrun passes for all eight packages.yapf -dr,isort,pylint --disable=Wandpytestpass for abstractions, andyapf,isortandpylintpass for http.