Skip to content

fix: Preserve type signature of annotated async functions - #203

Closed
edgarrmondragon wants to merge 2 commits into
mainfrom
fix/identity-transform-async-decorated
Closed

fix: Preserve type signature of annotated async functions#203
edgarrmondragon wants to merge 2 commits into
mainfrom
fix/identity-transform-async-decorated

Conversation

@edgarrmondragon

@edgarrmondragon edgarrmondragon commented Aug 28, 2026

Copy link
Copy Markdown

Version 2.4.0 (14bb92f) typed on_exception/on_predicate as Callable[[Callable[P, T]], Callable[P, T]], using ParamSpec/TypeVar to reconstruct the decorated callable's type.

For an async def function, mypy sees its real type as Callable[P, Coroutine[Any, Any, T]]. Reconstructing that type through the decorator's signature made mypy re-elaborate the Coroutine[Any, Any, T] generic, and disallow_any_decorated flagged its two Any parameters.

This is a regression from 2.2.1, which had typed the decorator as a plain identity transform (Callable[[_CallableT], _CallableT], _CallableT bound to Callable[..., Any]).

Closes #200

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@github-actions github-actions Bot added the fix Bug fix label Aug 28, 2026
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon
edgarrmondragon force-pushed the fix/identity-transform-async-decorated branch from a634ce3 to 1beb709 Compare August 28, 2026 19:38
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 backoff | 🛠️ Build #34281369 | 📁 Comparing 1beb709 against latest (0430374)

  🔍 Preview build  

1 file changed
± api/reference.html

@edgarrmondragon
edgarrmondragon deleted the fix/identity-transform-async-decorated branch August 28, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async decorator typing regression in 2.4.0 with mypy disallow_any_decorated

1 participant