Fix possible types for json parameter to Route.respond
According to the Python documentation, more than just strings, dicts, and lists can be encoded to JSON.
You're right @viccie30, though we need to align with the httpx api here, rather than python's, since thats what we're mocking.
Looks like httpx is typing json as Any, probably due to the option of switching in custom json library over build-int 🤔
Also, the python docs you're referring to touches encoding, e.g. python accepts tuples when dumping to json, but the response we're talking about here is about a loaded/decoded json ...
>>> json.loads(json.dumps(("httpx", "respx")))
['httpx', 'respx']
Looks like we've diverged from httpx on the request/encoding side as well .. also typed as Any
Also, the python docs you're referring to touches encoding, e.g. python accepts tuples when dumping to json, but the response we're talking about here is about a loaded/decoded json ...
Oh right, because this is mocking the returned value of httpx.Response's json property.
I think you're right therefore to copy httpx's annotations.
I think you're right therefore to copy httpx's annotations.
Yes, let's change to Any for the respond/response.
About the request/encoding side, I think we're fine with current typing. We're mimicking httpx api there as well, but we're not patching/mocking, but rather pattern matching encoded request json.
The current state of the art: https://github.com/python/typing/issues/182#issuecomment-1320974824
The current state of the art: python/typing#182 (comment)
Might be worth discussing, but since json.loads is typed to return Any, it may be incorrect to type it as your linked suggestion @g-as, even though I agree it would be neat.
Sticking with how httpx is typed is probably what we're "forced" to do .. maybe take your suggestion to a httpx and discuss the Any choice vs Json type there?