python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

Properties/Fields return the setter implementation

Open SoggyBottomBoy opened this issue 5 years ago • 0 comments

Environment data

  • Language Server version: XXX
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda Python 3.7

Code Snippet / Additional Information

class MySubClass():

    def __init__(self, a, b):
        self._a = a
        self._b = b

    @property
    def a(self) -> int:
        return self._a

    @a.setter
    def a(self, value: int):
        self._a = value

    @property
    def b(self) -> str:
        return self._b

    @b.setter
    def b(self, value: str):
        self._b = value


class MyClass():

    def __init__(self, arg1: MySubClass, arg2: MySubClass):

        self.prop1 = arg1
        self._prop2 = arg2

    @property
    def prop2(self) -> MySubClass:
        return self._prop2

    @prop2.setter
    def prop2(self, value: MySubClass):
        self._prop2 = value


my_sub_object_a = MySubClass(1, "a")
my_sub_object_b = MySubClass(2, "b")

my_object: MyClass = MyClass(my_sub_object_a, my_sub_object_b)

Behaviour

prop1 is correctly inferred as a value of type MySubClass, the autocompletion has the members of MySubClass available.

image image

prop2 is inferred as a method with the latest implementation (i.e. setter), as the setter method has no return there is no autocompletion on prop2

image image

Jedi

In comparison Jedi has the following behaviour: prop2 is still recognised as a method but has a return type of MySubClass

image

even though autocompletion still completes prop2 as a method by removing the parenthesis the field of prop2 are inferred

image

Apologies if this is a duplicate

SoggyBottomBoy avatar May 21 '20 23:05 SoggyBottomBoy