From a7bdffcb7c6f869390dc1a361202417e9b7ecc6d Mon Sep 17 00:00:00 2001 From: Carson Ip Date: Sun, 1 May 2022 23:36:27 +0100 Subject: [PATCH] Fix type hints --- h11/_connection.py | 2 +- h11/_readers.py | 2 +- h11/_state.py | 8 ++++++-- h11/_writers.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/h11/_connection.py b/h11/_connection.py index 75e5739..1696182 100644 --- a/h11/_connection.py +++ b/h11/_connection.py @@ -323,7 +323,7 @@ def _get_io_object( else: # General case: the io_dict just has the appropriate reader/writer # for this state - return io_dict.get((role, state)) # type: ignore + return io_dict.get((role, state)) # type: ignore[return-value] # This must be called after any action that might have caused # self._cstate.states to change. diff --git a/h11/_readers.py b/h11/_readers.py index 89545c2..08a9574 100644 --- a/h11/_readers.py +++ b/h11/_readers.py @@ -225,7 +225,7 @@ def expect_nothing(buf: ReceiveBuffer) -> None: ReadersType = Dict[ - Union[Sentinel, Tuple[Sentinel, Sentinel]], + Union[Type[Sentinel], Tuple[Type[Sentinel], Type[Sentinel]]], Union[Callable[..., Any], Dict[str, Callable[..., Any]]], ] diff --git a/h11/_state.py b/h11/_state.py index 2790768..3593430 100644 --- a/h11/_state.py +++ b/h11/_state.py @@ -226,9 +226,13 @@ class _SWITCH_CONNECT(Sentinel, metaclass=Sentinel): }, } +StateTransitionType = Dict[ + Tuple[Type[Sentinel], Type[Sentinel]], Dict[Type[Sentinel], Type[Sentinel]] +] + # NB: there are also some special-case state-triggered transitions hard-coded # into _fire_state_triggered_transitions below. -STATE_TRIGGERED_TRANSITIONS = { +STATE_TRIGGERED_TRANSITIONS: StateTransitionType = { # (Client state, Server state) -> new states # Protocol negotiation (MIGHT_SWITCH_PROTOCOL, SWITCHED_PROTOCOL): {CLIENT: SWITCHED_PROTOCOL}, @@ -345,7 +349,7 @@ def _fire_state_triggered_transitions(self) -> None: # Tabular state-triggered transitions joint_state = (self.states[CLIENT], self.states[SERVER]) changes = STATE_TRIGGERED_TRANSITIONS.get(joint_state, {}) - self.states.update(changes) # type: ignore + self.states.update(changes) if self.states == start_states: # Fixed point reached diff --git a/h11/_writers.py b/h11/_writers.py index 90a8dc0..939cdb9 100644 --- a/h11/_writers.py +++ b/h11/_writers.py @@ -125,7 +125,7 @@ def send_eom(self, headers: Headers, write: Writer) -> None: WritersType = Dict[ - Union[Tuple[Sentinel, Sentinel], Sentinel], + Union[Tuple[Type[Sentinel], Type[Sentinel]], Type[Sentinel]], Union[ Dict[str, Type[BodyWriter]], Callable[[Union[InformationalResponse, Response], Writer], None],