更新时间:2023-10-27 09:13:28
See here: http://www.wingware.com/doc/edit/helping-wing-analyze-code
Your IDE (Wing) doesn't know for sure what type of objects are in cars
, but you can tell it what car
is with an assert statement and it will do autocompletion exactly how you want it to. You can view it as casting the type for Wing's eyes only if you like.
class Reader:
def __init__(self):
"""Constructor"""
def ReadCarNames(self,cars):
for counter,car in enumerate(cars):
assert isinstance(car, Car) # this trains Wing
print str(counter) +' '+ car.name # autocompletion will work here
or if you don't want that assert firing off all the time, you can wrap it in 'if 0' logic that Wing's SourceAssistant picks up but python will not execute.
if 0: assert isinstance(car, Car)
You currently cannot tell Wing that a list/tuple/etc only contains one type of object and what it is, but it is in their plans and will use similar syntax.