microsoft / pyright

Static Type Checker for Python
Other
13.32k stars 1.45k forks source link

Cannot access property of generic parent class (ParamSpec) #2349

Closed Bluenix2 closed 3 years ago

Bluenix2 commented 3 years ago

Describe the bug I have a generic parent class with a property, when I then try to subclass this PyRight fails to find this property.

To Reproduce See the following code:

from typing import Callable, Generic
from typing_extensions import ParamSpec

P = ParamSpec('P')

class Hider(Generic[P]):
    """Hide a callable under a property."""

    __hidden: Callable[P, None]

    def __init__(self, value: Callable[P, None]) -> None:
        self.value = value

    @property
    def value(self) -> Callable[P, None]:
        return self.__hidden

    @value.setter
    def value(self, function: Callable[P, None]) -> None:
        self.__hidden = function

O = ParamSpec('O')

class Revealer(Hider[O]):
    def compare(self, func: Callable[O, None]) -> bool:
        """Compare the names with the hidden callable."""
        print(dir(self))
        return self.value.__name__ == func.__name__  # Cannot access member "value" for type "Revealer[O@Revealer]"

Expected behavior When I run this it in-fact works, so I would expect PyRight to let this pass as well.

VS Code extension or command-line

Released on
22/03/2019, 04:10:23
Last updated
25/09/2021, 06:09:18
Identifier
ms-pyright.pyright

Additional context ParamSpec is being imported from typing_extensions.

When I remove the variable and just inherit from Hider (class Revealer(Hider):) it works. When I change it from being a property it also works.

erictraut commented 3 years ago

Thanks for the bug report. This will be fixed in the next release.

erictraut commented 3 years ago

This is addressed in pyright 1.1.172, which I just published. It will also be in the next release of pylance.