Open
Description
We recently hit an error using @wraps
on a class method in Trio: python-trio/trio#2775 (comment) when checked with pyright. It works fine on mypy, but I'm guessing they might be special-casing wraps usage while pyright doesn't.
Minimal repro (python 3.11):
from functools import wraps
from typing import assert_type
def foo(param: int) -> str:
"""docstring"""
return ""
@wraps(foo)
def my_function(blah: int) -> str:
return 'foo'
# works fine
assert_type(my_function(5), str)
class MyOtherClass:
def bar(self, param: int) -> str:
"""docstring"""
return ""
class MyClass:
@wraps(MyOtherClass.bar)
def my_method(self, blah: int) -> str:
return 'foo'
instance = MyClass()
# works in mypy, but not pyright
assert_type(instance.my_method(5), str)
mypy 1.5.1 works without any issue, pyright 1.1.325 gives
./test.py
./test.py:26:13 - error: Argument missing for parameter "blah" (reportGeneralTypeIssues)
./test.py:26:13 - error: "assert_type" mismatch: expected "str" but received "Unknown" (reportGeneralTypeIssues)
2 errors, 0 warnings, 0 informations
This smells a lot like the problem with getting functools.cache to work both with methods and functions, see e.g. #6347
Metadata
Metadata
Assignees
Labels
No labels