Skip to content

False positive "Argument missing for parameter "self"? #6669

Closed Answered by erictraut
sergeykorablin asked this question in Q&A
Discussion options

You must be logged in to vote

This is a bug in the python-telegram-bot library. The send_message function is decorated with @_log, and the _log function is not properly annotated. If it were completely unannotated, pyright would infer its type correctly, but it is partially annotated, so pyright assumes that it shouldn't override the intent of the author.

The correct way to type _log is to use a TypeVar bound to a Callable or a Callable with a ParamSpec.

    # Option 1: TypeVar bound to a Callable
    T = TypeVar("T", bound=Callable[..., Any])

    def _log(func: T) -> T: ...

    # Option 2: Callable with a ParamSpec
    P = ParamSpec("P")
    R = TypeVar("R")

    def _log(func: Callable[P, R]) -> Callable[P, R]: ...

Replies: 2 comments 1 reply

Comment options

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

Answer selected by sergeykorablin
Comment options

You must be logged in to vote
0 replies
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