ITADN

[TSP] Pyrefly: hover on an unannotated @property infers return type as Any (requests Response)

#8096Closedrchiodo 创建于 2026-06-30
team needs to reproduce
R
rchiodocommented
[TSP] Found via differential testing comparing Pylance's built-in Pyright analyzer against [Pyrefly](https://github.com/facebook/pyrefly) running as an external type server over the Type Server Protocol (TSP). ## Summary On hover, Pyrefly types the return of an **unannotated `@property` getter** as `Any`, whereas Pylance's built-in analyzer infers the real return type from the `return` statements. The inferred property type is lost. ## Repro 1. `git clone https://github.com/psf/requests.git` 2. `git checkout 0e322af87745eff34caffe4df68456ebc20d9068` (v2.32.3) 3. Create a venv and `pip install -e .` 4. Open `src/requests/models.py`. 5. Hover over the property names `ok` and `apparent_encoding`: ```py @property def ok(self): ... return True @property def apparent_encoding(self): ... return "utf-8" ``` To switch backends: set `python.analysis.typeServerExecutable` to the Pyrefly binary to get the Pyrefly result; leave it unset to get the built-in (Pyright) result. ## Expected (Pylance / built-in Pyright) ```python (property) ok: (self: Self@Response) -> bool ``` ```python (property) apparent_encoding: (self: Self@Response) -> (Any | Literal['utf-8']) ``` ## Actual (Pyrefly over TSP) ```python (property) ok: (self: Self@Response) -> Any ``` ```python (property) apparent_encoding: (self: Self@Response) -> Any ``` Both property return types collapse to `Any` instead of the inferred type. ## Environment - Pyrefly: `pyrefly 1.1.1` - `python.analysis` Python version: 3.11 - OS: Windows
关闭于 2026-07-02 1 条评论