Document Return Types of RequestData Members (#4396)

This commit is contained in:
Bibo-Joshi 2024-08-02 13:41:39 +02:00 committed by GitHub
parent af76a8485f
commit a967dbe37a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,6 +55,9 @@ class RequestData:
a single object of type :obj:`int`, :obj:`float`, :obj:`str` or :obj:`bool` or any
(possibly nested) composition of lists, tuples and dictionaries, where each entry, key
and value is of one of the mentioned types.
Returns:
Dict[:obj:`str`, Union[:obj:`str`, :obj:`int`, List[any], Dict[any, any]]]
"""
return {
param.name: param.value # type: ignore[misc]
@ -71,6 +74,9 @@ class RequestData:
By default, this property uses the standard library's :func:`json.dumps`.
To use a custom library for JSON encoding, you can directly encode the keys of
:attr:`parameters` - note that string valued keys should not be JSON encoded.
Returns:
Dict[:obj:`str`, :obj:`str`]
"""
return {
param.name: param.json_value
@ -84,6 +90,9 @@ class RequestData:
Args:
encode_kwargs (Dict[:obj:`str`, any], optional): Additional keyword arguments to pass
along to :func:`urllib.parse.urlencode`.
Returns:
:obj:`str`
"""
if encode_kwargs:
return urlencode(self.json_parameters, **encode_kwargs)
@ -97,6 +106,9 @@ class RequestData:
url (:obj:`str`): The URL the parameters will be attached to.
encode_kwargs (Dict[:obj:`str`, any], optional): Additional keyword arguments to pass
along to :func:`urllib.parse.urlencode`.
Returns:
:obj:`str`
"""
url_parameters = self.url_encoded_parameters(encode_kwargs=encode_kwargs)
return f"{url}?{url_parameters}"
@ -109,6 +121,9 @@ class RequestData:
By default, this property uses the standard library's :func:`json.dumps`.
To use a custom library for JSON encoding, you can directly encode the keys of
:attr:`parameters` - note that string valued keys should not be JSON encoded.
Returns:
:obj:`bytes`
"""
return json.dumps(self.json_parameters).encode(TextEncoding.UTF_8)