From 1959679380700a9c1318353655b34aadab27713e Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Sat, 29 Jan 2022 15:47:09 -0600 Subject: [PATCH 1/2] use explicit Optional[...] for paramters with None as a default See https://www.python.org/dev/peps/pep-0484/\#id29 --- starlette/datastructures.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/starlette/datastructures.py b/starlette/datastructures.py index 2c5c4b016..e51f68b9b 100644 --- a/starlette/datastructures.py +++ b/starlette/datastructures.py @@ -13,7 +13,10 @@ class URL: def __init__( - self, url: str = "", scope: Scope = None, **components: typing.Any + self, + url: str = "", + scope: typing.Optional[Scope] = None, + **components: typing.Any, ) -> None: if scope is not None: assert not url, 'Cannot set both "url" and "scope".' @@ -492,9 +495,9 @@ class Headers(typing.Mapping[str, str]): def __init__( self, - headers: typing.Mapping[str, str] = None, - raw: typing.List[typing.Tuple[bytes, bytes]] = None, - scope: Scope = None, + headers: typing.Optional[typing.Mapping[str, str]] = None, + raw: typing.Optional[typing.List[typing.Tuple[bytes, bytes]]] = None, + scope: typing.Optional[typing.Mapping[str, str]] = None, ) -> None: self._list: typing.List[typing.Tuple[bytes, bytes]] = [] if headers is not None: @@ -657,7 +660,9 @@ class State: Used for `request.state` and `app.state`. """ - def __init__(self, state: typing.Dict = None): + _state: typing.Dict[str, typing.Any] + + def __init__(self, state: typing.Optional[typing.Dict[str, typing.Any]] = None): if state is None: state = {} super().__setattr__("_state", state) From 888b3303fb61db88f2d83995ae69e2a7d54174fd Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Sat, 29 Jan 2022 15:50:44 -0600 Subject: [PATCH 2/2] fix type annotations for scope --- starlette/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starlette/datastructures.py b/starlette/datastructures.py index e51f68b9b..b3ae20ca5 100644 --- a/starlette/datastructures.py +++ b/starlette/datastructures.py @@ -497,7 +497,7 @@ def __init__( self, headers: typing.Optional[typing.Mapping[str, str]] = None, raw: typing.Optional[typing.List[typing.Tuple[bytes, bytes]]] = None, - scope: typing.Optional[typing.Mapping[str, str]] = None, + scope: typing.Optional[typing.Mapping[str, typing.Any]] = None, ) -> None: self._list: typing.List[typing.Tuple[bytes, bytes]] = [] if headers is not None: