I've been using the lazy-property library (https://pypi.org/project/lazy-property/) for a while. It works perfectly, but in my editor these lazy properties don't give any autocompletions.
My setup is Atom, using the ide-python package (https://github.com/lgeiger/ide-python), which is driven by the python-language-server (https://github.com/palantir/python-language-server), which uses Jedi (https://github.com/davidhalter/jedi) for autocompletions.
Basically, this issue should be reproducible in any Jedi-based autocompletion context.
I've been wondering if there's a way the code in lazy-property could be rewritten (maybe using type-hints and whatnot) such that Jedi could understand that the type coming from a lazy-property-decorated method should be the same as if the decorator were absent.
The implementation for this decorator is actually super simple, it's basically just:
class lazy_property(property):
def __init__(self, method, fget=None, fset=None, fdel=None, doc=None):
self.method = method
self.cache_name = f"_{self.method.__name__}"
doc = doc or method.__doc__
super().__init__(fget=fget, fset=fset, fdel=fdel, doc=doc)
update_wrapper(self, method)
def __get__(self, instance, owner):
if instance is None:
return self
if hasattr(instance, self.cache_name):
result = getattr(instance, self.cache_name)
else:
if self.fget is not None:
result = self.fget(instance)
else:
result = self.method(instance)
setattr(instance, self.cache_name, result)
return result
Does anyone have any ideas of how I could refactor this class in order to get Jedi to understand that it should assume that the decorator does not change the typing of the return values?
Any help would be massively appreciated, cheers.