Skip to content

Commit

Permalink
Fix type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip authored and pgjones committed Aug 25, 2022
1 parent 04cc0f7 commit a7bdffc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion h11/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion h11/_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]],
]

Expand Down
8 changes: 6 additions & 2 deletions h11/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion h11/_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit a7bdffc

Please sign in to comment.