class A:
pass
class HasAnA:
def __init__(self, a):
self._a = a
def get_a(self):
return self._a
class Thing:
def __init__(self, item: A | HasAnA):
self._item: A
if isinstance(item, A):
self._item = item
else:
self._item = item.get_a()
assert isinstance(item, HasAnA)
def method(self):
# self._item. --> tab completes into:
self._item.get_a()
When the member self._item is declared and assigned as above, pylsp seems to be confused about the type (Can I verify this somehow?)
When I try to tab complete after self._item. (see above) pylsp suggests the method get_a, which is not available on an instance of A.
I tried to clarify and change some types in the example, but the behavior stayed. Is there some other way to rewrite the inside of class Thing so that pylsp unserstands the type correctly?
When the member
self._itemis declared and assigned as above, pylsp seems to be confused about the type (Can I verify this somehow?)When I try to tab complete after
self._item.(see above) pylsp suggests the methodget_a, which is not available on an instance of A.I tried to clarify and change some types in the example, but the behavior stayed. Is there some other way to rewrite the inside of
class Thingso that pylsp unserstands the type correctly?