Skip to content

Commit

Permalink
Enhance type of headers.get method.
Browse files Browse the repository at this point in the history
When given a default value that is not None, the get method always
returns a string.
  • Loading branch information
pcorpet committed May 16, 2021
1 parent 1104012 commit 625aaba
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Expand Up @@ -14,6 +14,7 @@ Unreleased
decorated with it report the correct type. :issue:`2113`
- Fix multipart parsing bug when boundary contains special regex
characters. :issue:`2125`
- Enhance type annotation for ``headers.get``. :issue:`2128`


Version 2.0.0
Expand Down
2 changes: 2 additions & 0 deletions src/werkzeug/datastructures.pyi
Expand Up @@ -220,6 +220,8 @@ class Headers(Dict[str, str]):
def __getitem__(self, key: str, _get_mode: Literal[True] = ...) -> str: ...
def __eq__(self, other: object) -> bool: ...
@overload # type: ignore
def get(self, key: str, default: str) -> str: ...
@overload
def get(self, key: str, default: Optional[str] = None) -> Optional[str]: ...
@overload
def get(
Expand Down
2 changes: 1 addition & 1 deletion src/werkzeug/sansio/request.py
Expand Up @@ -491,7 +491,7 @@ def user_agent(self) -> UserAgent:
Werkzeug 2.1. A ``UserAgent`` subclass must be set to parse
data from the string.
"""
return self.user_agent_class(t.cast(str, self.headers.get("User-Agent", "")))
return self.user_agent_class(self.headers.get("User-Agent", ""))

# Authorization

Expand Down

0 comments on commit 625aaba

Please sign in to comment.