Using TypedDict to type check **kwargs #3123
igorp-collabora
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
I'm a bit torn on this, because being able to provide API parameters for arbitrary endpoints directly as function arguments makes this library more convenient to use and the user code more pythonic. On the other hand I assume without moving to |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently the most of the methods that have an underlying HTTP request takes a
**kwargs: Any
arguments that passed down to the HTTP handling functions. For example, it can betimeout
orextra_headers
.However, because they are using
Any
there is no type checking on the arguments used. This means a wrong argument name can be used.To type hint
**kwargs
aTypedDict
combined withUnpack
can be used:https://peps.python.org/pep-0692/
https://docs.python.org/3/library/typing.html#typing.Unpack
One of the issues implementing this can be that all unused
kwargs
will be converted in to an HTTP query args in thehttp_request
function. However, there is already aquery_parameters
argument that was added to avoid collisions. Maybe make thequery_parameters
the official way of adding extra http query and leave the extra kwargs only for backwards compatibility.Beta Was this translation helpful? Give feedback.
All reactions