List Of Class Method Not Autocompleting In PyCharm
Solution 1:
The reason is that python has dynamic typing. There is no constraint that myList must contain ONLY foo objects. So PyCharm can't know that myList[0] is a foo to give you the autocomplete for foo (that's only known at runtime).
Take this example:
class foo(object):
def __init__(self):
self.num = 10
def getNum(self):
return self.num
class bar(object):
def __init__(self):
self.num = 10
def getNum2(self):
return self.num
myList = []
myList.append(foo())
myList.append(bar())
print(myList[0])
PyCharm doesn't know whether to give you the autocomplete for foo() or bar() so it doesn't give you either.
The last case regarding x works because you explicitly assigned x as a foo object, so Pycharm knows and gives you the autocomplete for foo.
Solution 2:
Im pretty sure this is an IDE issue as it may not trace the variable all the way back to its original calls until actually ran. so with you setting x directly to foo() was one assignment but setting y = myList[0] and then getting the object at myList[0] which would be another call back to the variable if that makes sense.
Solution 3:
From python 3.5, you can use typing
which provides advanced typing feature that pyCharm can use to suggest autocompletion.
see https://stackoverflow.com/a/59971921/2696355 for an example and the typing
doc for more information
Post a Comment for "List Of Class Method Not Autocompleting In PyCharm"