Add support for python descriptor protocol
As of version 0.5.30.0 the language server does not seem to support the python descriptor protocol, that allows definition of functions similar to the @property decorator. The documentation for this on the python docs is https://docs.python.org/3/howto/descriptor.html
Example:
class memoized_property:
def __init__(self, fGet):
self.fGet = fGet
def __get__(self, instance, class_=None):
if instance is None:
return self
instance.__dict__[self.__name__] = res = self.fGet(instance)
return res
class Foo:
@memoized_property
def i_only_run_once(self) -> str:
# long expensive stuff here
return 'once'
foo = Foo()
value = foo.i_only_run_once
value is 'once' here, but the inferred type is the function Foo.i_only_run_once() -> str, since the language server thinks that i_only_run_once is a function.
Calling it foo.i_only_run_once() makes the inferred type be str, but it will obviously cause a runtime error.
Using @property instead of @memoized_property works as expected.
I'm using vscode 1.42.1 and the language server 0.5.30.0
For reference, @property is special cased in the analysis. Custom decorators like this are not supported to this extent, hence why the decorator doesn't have any effect.
I figured as much, since @property is far more common.
It would be nice if it could be supported though.
Just wanted to mention that the same behavior happens on the cached_property in the standard lib