Property in a PEP 695 generic class is reported as redeclared when its type is an alias that refers back to the class
Describe the bug
In a class declared with PEP 695 syntax (class Op[T]:), a property whose type is a type alias that refers back to the class is not recognized as a property while the class itself is being checked. Pyright reports that the getter is "obscured by a declaration of the same name", and that .setter cannot be accessed on FunctionType.
The same class written with Generic[T] and a TypeVar is accepted. Code that uses the class is not affected: from outside, the property has the right type and assigning to it is checked correctly. It happens in both .py (Python 3.14) and .pyi files, and whether or not the alias uses the type statement.
Code or Screenshots
from collections.abc import Callable
class Op[T]:
@property
def completed(self) -> Handler[T]: ...
@completed.setter
def completed(self, value: Handler[T]) -> None: ...
type Handler[T] = Callable[[Op[T], int], object]
repro.py:6:9 - error: Method declaration "completed" is obscured by a declaration of the same name (reportRedeclaration)
repro.py:7:16 - error: Cannot access attribute "setter" for class "FunctionType"
Attribute "setter" is unknown (reportFunctionMemberAccess)
2 errors, 0 warnings, 0 informations
Expected: no errors, as with the equivalent class Op(Generic[T]):.
This comes up in generated type stubs for WinRT (PyWinRT), where an async operation's completed property is typed with a handler alias that takes the operation itself.
VS Code extension or command-line
Command line, pyright 1.1.414, "pythonVersion": "3.14".
Hi, I would like to work on this. I will investigate a focused fix and add regression coverage shortly.
I tested the exact PEP 695 property/type-alias reproduction against current main using the analyzer test harness, and it now reports zero errors. I am releasing the claim because the issue appears already resolved on main and no patch is needed.
This still reproduces on main (fbaf3ddc8) from the command line, for the .py repro at 3.12–3.14 and for .pyi files with either the type statement or a plain alias:
repro.py:6:9 - error: Method declaration "completed" is obscured by a declaration of the same name (reportRedeclaration)
repro.py:7:16 - error: Cannot access attribute "setter" for class "FunctionType"
I think the test harness hides it: typeAnalyzeSampleFiles sets a pre-check callback that runs NameTypeWalker over the file before checking, which evaluates the names in a different order. With the repro as a sample file, typeAnalyzeSampleFiles reports no errors on both 1.1.414 and main, but the same Program driven without setPreCheckCallback reports both errors on both. So it looks order-dependent rather than fixed — a regression test would need to run without the pre-check walk (or check that the walk doesn't change the result).
@dlech I was just about to comment the exact same thing. The test harness evaluates in a different order than the CLI. I was able to reproduce the bug on a current build of main.