Revision history [back]
One approach is always to run to a breakpoint with the results you expect and then write / edit code. Unit tests can be a good way to quickly and repeatedly run the debugger to a certain point.
If you want to use type hints to inform Wing's static analyzer what the attributes are, you probably need to define new classes. For example, if the generic results retrieval looks something like (note that this is made-up, untested code) --
class Results:
def getsourcefilename(self) -> str:
...
def getresults(filename) -> Results:
...
And your results have a name and an address fields, you could do something like:
class MyResults(Results):
name: str
address: str
def dosomething(filename: str) -> MyResults:
results: MyResults
results = getresults(filename)
... # Do something with results
The above should be enough for Wing to add the attributes to the autocomplete popup, but the MyResults class won't be used at runtime and other type checkers (mypy, pytype, ....) will probably complain about it. This might be better (though the details probably depend on the library that you use) --
def dosomething(filename: str) -> MyResults:
results: MyResults
results = getresults(filename) # type: ignore
results.__class__ = MyResults # type: ignore
... # Do something with results