pyrefly errors on decorator call even though equivalent regular call succeeds.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 516
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
This type checks with `mypy`, `pyright`, `ty` and `zuban`, but `pyrefly` errors on using `decorator` as a decorator, even though the equivalent regular function call succeeds
```python
from typing import Any, Protocol
class Polymorphism(Protocol):
def __call__[T: Any](self, obj: T, /) -> T: ...
def decorator(deco: Polymorphism) -> Polymorphism:
return deco
def foo[T: int](arg: T) -> T:
raise NotImplementedError
decorator(foo) # OK
@decorator # ERROR
def bar[T: int](arg: T) -> T:
raise NotImplementedError
```
This example was derived from some custom decorator factory code.
```
ERROR sandbox.py:14:1-11: Argument `(arg: T) -> T` is not assignable to parameter `deco` with type `Polymorphism` in function `decorator` [bad-argument-type]
```
### Sandbox Link
https://pyrefly.org/sandbox/?project=v2.pZRNC4MwDIb_SsCDDoa9977D2EERb0PEaVFhGmndYP9-aWv9YCBsu0nSJJI87_utZTpfW-QU4_3VoRyaVnWBSzuOrLpKWl2eX1Oue2STMoheDukRmIGEcmEYOglUokRjSoH-4psZ5vk64A5lcdUFs5IQ9VCiIguMENNp1uq0hOd41n7QiZ6OMpO8_AJ1OQB4EF2sCbmEjp2SJErssFshfxz2SZIHsQ3AdBTyUEKwftBgQov25JFJC2jGcVCcMVeOsmaiZxWWim0qGO1CQvEsWuP_23aAhnxFbf9B2LcE-3sA-5pferHL5Bs
### (Only applicable for extension issues) IDE Information
_No response_
Contributor guide
Research direction
Reproduce the diagnostic from the sandbox.py example using the linked sandbox, then compare how decorator application is checked with the equivalent regular call. Add a regression test for the generic Protocol-based decorator example and confirm that the decorator form no longer reports bad-argument-type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100