Skip to content

Pylance error when using a @retry decorator on a function #5035

Closed
@hudcap

Description

@hudcap

Asked on SO here with no response.
There are discussions about decorators (python/mypy#1551, python/mypy#3157) that are above my head, but it seems that my use-case was solved.

I'm not sure if I'm reporting a bug or my stupidity, but...

I have a function that runs some code based on random variables. There are some assertion checks on the random variables, so I use a @retry decorator from the retry pip package on the function. Everything works perfectly.

MWE:

from retry import retry

@retry()
def foo():
    pass

However, I started using pylance in VS Code with type checking set to "basic" and it's throwing the following error:

Argument of type "() -> None" cannot be assigned to parameter of type "_T@_Decorator"
  Type "() -> None" cannot be assigned to type "_T@_Decorator"

The stub being used is https://github.com/python/typeshed/blob/master/stubs/retry/retry/api.pyi

From my beginner's understanding, it looks right, and if I change the second line here from

_T = TypeVar("_T", bound=Callable[..., Any])
_Decorator = Callable[[_T], _T]

to

_T = TypeVar("_T", bound=Callable[..., Any])
_Decorator = Callable[[Callable[..., Any]], _T]

it's happy, which doesn't make any sense to me, since _T should not be any "stricter" than its bound.
So either there's an issue, or I'm in over my head and completely lost.

I'm new to type checking and trying to learn, so please go easy on me... :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions