def json_field(self, name:str):
"""
Convenience method to access field 'name' in the JSON.
"""
self._ensure_fetched()
json = cast(dict, self._json)
return json.get(name)
However, it appears that self._json is an httpx.Response.
def _ensure_fetched(self):
"""
Make sure the uri has been dereferenced.
Note: this could potentially be a smart factory, but currently it is not because
we'd have to figure out when to expire the cache and that has some time.
"""
if not self._json:
self._json = httpx.get(...)
The get operation is not valid for an httpx.Response. The cast in json_field doesn't do a type conversion to a dict. It just overrides the type hint.
I'm not sure what the intention is here, but it seems that self._json should be typed as a dict|None and be set to httpx.Response.json? It may make sense to initialize the self._json in the constructor and avoid the None checking.
In 'AnyObject', 'json_field' is defined like:
However, it appears that
self._json
is anhttpx.Response
.The
get
operation is not valid for anhttpx.Response
. Thecast
injson_field
doesn't do a type conversion to adict
. It just overrides the type hint.I'm not sure what the intention is here, but it seems that
self._json
should be typed as adict|None
and be set tohttpx.Response.json
? It may make sense to initialize theself._json
in the constructor and avoid theNone
checking.