Open
Conversation
When TypeVars have value restrictions (e.g., TypeVar("T", str, bytes)),
mypy expands them into concrete variants for type checking. However,
after checking, the function type was left as the last expanded variant
rather than the original polymorphic signature.
This commit preserves the original generic signature after checking
functions with constrained TypeVars.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When a decorator with constrained TypeVars is applied to a function with matching constrained TypeVars, the decorator's TypeVars need to be matched with the function's TypeVars to preserve the polymorphic signature. This change: - Adds TypeVar matching logic in visit_decorator_inner that maps decorator TypeVars to function TypeVars with matching constraints - Preserves constrained TypeVars through infer_function_type_arguments by detecting matching TypeVars and applying polymorphic inference - Adds helper methods _finalize_poly_result and _build_typevar_substitution_map to handle the polymorphic result Fixes cases where decorated functions with constrained TypeVars would incorrectly collapse to concrete types instead of maintaining their polymorphic signatures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When an overloaded decorator is applied to a function with constrained TypeVars, the function is expanded into its constraint variants, each is matched against the appropriate overload, and the results are combined into an Overloaded return type. This change adds: - is_overload_decorator_constrained_call: detects when an overloaded decorator is applied to a constrained TypeVar function - has_constrained_typevars: helper to check for constrained TypeVars - handle_overload_decorator_constrained_call: expands and matches variants This is the reverse case of is_generic_decorator_overload_call, which handles a generic decorator applied to an overloaded function. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When a function has both constrained TypeVars and @types.coroutine or @asyncio.coroutine decorator, the coroutine's AwaitableGenerator return type wrapper was being lost during signature restoration. This change applies the AwaitableGenerator transformation to the restored polymorphic signature, preserving both the polymorphism and the coroutine wrapper. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
No description provided.