Skip to content

Commit

Permalink
override http.HTTPMessage methods to only use str for the header …
Browse files Browse the repository at this point in the history
…type (#11114)
  • Loading branch information
Avasam authored Dec 19, 2023
1 parent 7bdf6ba commit cf6bafb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions stdlib/http/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ responses: dict[int, str]

class HTTPMessage(email.message.Message):
def getallmatchingheaders(self, name: str) -> list[str]: ... # undocumented
# override below all of Message's methods that use `_HeaderType` / `_HeaderTypeParam` with `str`
# `HTTPMessage` breaks the Liskov substitution principle by only intending for `str` headers
# This is easier than making `Message` generic
def __getitem__(self, name: str) -> str | None: ...
def __setitem__(self, name: str, val: str) -> None: ... # type: ignore[override]
def values(self) -> list[str]: ...
def items(self) -> list[tuple[str, str]]: ...
@overload
def get(self, name: str, failobj: None = None) -> str | None: ...
@overload
def get(self, name: str, failobj: _T) -> str | _T: ...
@overload
def get_all(self, name: str, failobj: None = None) -> list[str] | None: ...
@overload
def get_all(self, name: str, failobj: _T) -> list[str] | _T: ...
def replace_header(self, _name: str, _value: str) -> None: ... # type: ignore[override]
def set_raw(self, name: str, value: str) -> None: ... # type: ignore[override]
def raw_items(self) -> Iterator[tuple[str, str]]: ...

def parse_headers(fp: io.BufferedIOBase, _class: Callable[[], email.message.Message] = ...) -> HTTPMessage: ...

Expand Down

0 comments on commit cf6bafb

Please sign in to comment.