microsoft / pyright

Static Type Checker for Python
Other
13.48k stars 1.48k forks source link

cached_property self type #9464

Open cole-dda opened 1 week ago

cole-dda commented 1 week ago

Environment data

Code Snippet

class CachedBug:

    @cached_property
    def x(self)->int:
        return 0

    @cached_property
    def y(self)->str:
        return ''

    @cached_property
    def z(self)->Self:
        return self.__class__()

    @cached_property
    def a(self)->'CachedBug':
        return CachedBug()

def usage():
    bug = CachedBug()
    #x is int,ok
    x = bug.x
    #y is str,ok
    y = bug.y

    #z is Any,not ok
    z = bug.z

    #a is CachedBug,ok
    a = bug.a

Repro Steps

  1. use vscode open python file

Expected behavior

pylance can know "z" is CachedBug type

Actual behavior

"z" is Any type

Logs

XXX
erictraut commented 1 week ago

Could someone from the pylance team please transfer this to the pyright project? Thanks!