]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
use explicit Optional[...] for parameters with None as a default in datastructures...
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Mon, 31 Jan 2022 09:35:58 +0000 (03:35 -0600)
committerGitHub <noreply@github.com>
Mon, 31 Jan 2022 09:35:58 +0000 (10:35 +0100)
* use explicit Optional[...] for paramters with None as a default

See https://www.python.org/dev/peps/pep-0484/\#id29

* fix type annotations for scope

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
starlette/datastructures.py

index 677db027b9df489c438e9cd77dcdc7d4b3b0a78f..ae2d9803a3510a330b79f6d8a4a2be9db08068c3 100644 (file)
@@ -15,7 +15,10 @@ class Address(typing.NamedTuple):
 
 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".'
@@ -494,9 +497,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, typing.Any]] = None,
     ) -> None:
         self._list: typing.List[typing.Tuple[bytes, bytes]] = []
         if headers is not None:
@@ -659,7 +662,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)