Skip to content

Conversation

@nkemnitz
Copy link

No description provided.

nkemnitz and others added 4 commits December 21, 2025 23:25
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants