Skip to content

Help with "ParamSpec is unbound" mypy error in decorator for sync + async functions #1970

Answered by Daverball
FelixSiegel asked this question in Q&A
Discussion options

You must be logged in to vote

You need to add annotations to your implementation signature as well, since mypy will use those annotations to check the body.

Note the use of Any for the implementation for the Callable return type, this reduces type safety slightly in the implementation, but if you try to use a union of the two overloads instead, you will end up with errors in other places, since mypy can't figure out the relationship between the two overloads.

from typing import Any, Callable, ParamSpec, TypeVar, Awaitable, overload
import asyncio
import functools

Param = ParamSpec("Param")
RetType = TypeVar("RetType")

class Logger:
    @overload
    @classmethod
    def catch_errors(
        cls, func: Callable[Param, 

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@FelixSiegel
Comment options

Comment options

You must be logged in to vote
1 reply
@FelixSiegel
Comment options

Answer selected by FelixSiegel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants