Remove the default argument to all uses of getlist
in Sanic in case none are found. Previously it defaulted to returning None
. Instead return an empty list which is sensible and avoids ambiguity with return types.
This commit is contained in:
parent
a5a9658896
commit
b692309c91
|
@ -149,13 +149,11 @@ class CookieRequestParameters(RequestParameters):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return super().get(name, default)
|
return super().get(name, default)
|
||||||
|
|
||||||
def getlist(
|
def getlist(self, name: str) -> list[Any]:
|
||||||
self, name: str, default: Optional[Any] = None
|
|
||||||
) -> Optional[Any]:
|
|
||||||
try:
|
try:
|
||||||
return self._get_prefixed_cookie(name)
|
return self._get_prefixed_cookie(name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return super().getlist(name, default)
|
return super().getlist(name)
|
||||||
|
|
||||||
def _get_prefixed_cookie(self, name: str) -> Any:
|
def _get_prefixed_cookie(self, name: str) -> Any:
|
||||||
getitem = super().__getitem__
|
getitem = super().__getitem__
|
||||||
|
|
|
@ -19,15 +19,14 @@ class RequestParameters(dict):
|
||||||
return super().get(name, [default])[0]
|
return super().get(name, [default])[0]
|
||||||
|
|
||||||
def getlist(
|
def getlist(
|
||||||
self, name: str, default: Optional[Any] = None
|
self, name: str
|
||||||
) -> Optional[Any]:
|
) -> list[Any]:
|
||||||
"""Return the entire list
|
"""Return the entire list
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): The name of the parameter
|
name (str): The name of the parameter
|
||||||
default (Optional[Any], optional): The default value. Defaults to None.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Optional[Any]: The entire list
|
list[Any]: The entire list of values or [] if not found
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
return super().get(name, default)
|
return super().get(name) or []
|
||||||
|
|
|
@ -445,10 +445,10 @@ def test_cookie_accessors(app: Sanic):
|
||||||
"four": request.cookies.get("four", "fallback"),
|
"four": request.cookies.get("four", "fallback"),
|
||||||
},
|
},
|
||||||
"getlist": {
|
"getlist": {
|
||||||
"one": request.cookies.getlist("one", ["fallback"]),
|
"one": request.cookies.getlist("one"),
|
||||||
"two": request.cookies.getlist("two", ["fallback"]),
|
"two": request.cookies.getlist("two"),
|
||||||
"three": request.cookies.getlist("three", ["fallback"]),
|
"three": request.cookies.getlist("three"),
|
||||||
"four": request.cookies.getlist("four", ["fallback"]),
|
"four": request.cookies.getlist("four"),
|
||||||
},
|
},
|
||||||
"getattr": {
|
"getattr": {
|
||||||
"one": request.cookies.one,
|
"one": request.cookies.one,
|
||||||
|
@ -484,7 +484,7 @@ def test_cookie_accessors(app: Sanic):
|
||||||
"one": ["1"],
|
"one": ["1"],
|
||||||
"two": ["2"],
|
"two": ["2"],
|
||||||
"three": ["3"],
|
"three": ["3"],
|
||||||
"four": ["fallback"],
|
"four": [],
|
||||||
},
|
},
|
||||||
"getattr": {
|
"getattr": {
|
||||||
"one": "1",
|
"one": "1",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user