I have a function that accesses an API and returns its JSON:
def get_api():
return requests.get(url).json()
Such response is of this type:
[{id: 3, name: 'X'},{id: 7, name: 'Y'},...]
I would like to declare the type of the return value so that the linting is aware of that, so when I write:
r=get_api()
for e in r:
print(e["id"]) # linting ok
print(e["something"]) # linting error, 'something' is not a valid key
The JSON is simple here, but can be nested of course.
I'm using Python 3.6.
How should I use the typings?