Skip to content

Preserve type when applying optimize_mapper#240

Merged
inducer merged 1 commit intomainfrom
optimize-mapper-typing
Feb 27, 2026
Merged

Preserve type when applying optimize_mapper#240
inducer merged 1 commit intomainfrom
optimize-mapper-typing

Conversation

@inducer
Copy link
Owner

@inducer inducer commented Feb 27, 2026

cc @majosm

Copilot AI review requested due to automatic review settings February 27, 2026 15:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve type preservation for the optimize_mapper decorator by using a TypeVar instead of plain type annotations. The decorator applies AST rewriting to mapper classes to optimize their performance, and the change attempts to ensure that type checkers understand that the decorator returns the same class type that was passed in.

Changes:

  • Introduced a TypeVar MapperT to represent mapper classes
  • Updated the return type of optimize_mapper from Callable[[type], type] to Callable[[MapperT], MapperT]
  • Updated the internal wrapper function and cast operation to use MapperT

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@inducer inducer merged commit 5de6f00 into main Feb 27, 2026
14 checks passed
@inducer inducer deleted the optimize-mapper-typing branch February 27, 2026 18:33
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