From e6f417b897eb67cd926ad6e98ee90448fccb502c Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Tue, 22 Sep 2020 13:20:18 -0700 Subject: [PATCH] Change signature of getRawHeaders() --- src/twisted/web/http_headers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/twisted/web/http_headers.py b/src/twisted/web/http_headers.py index 525965e4aa5..0a84a04a495 100644 --- a/src/twisted/web/http_headers.py +++ b/src/twisted/web/http_headers.py @@ -14,7 +14,9 @@ Mapping, Optional, Sequence, + TypeVar, Tuple, + Union, ) from collections.abc import Sequence as _Sequence @@ -222,9 +224,11 @@ def addRawHeader(self, name: AnyStr, value: AnyStr) -> None: self.setRawHeaders(name, values) + _T = TypeVar("_T") + def getRawHeaders( - self, name: AnyStr, default: List[AnyStr] = None - ) -> Optional[List[AnyStr]]: + self, name: AnyStr, default: Optional[_T] = None + ) -> Union[List[AnyStr], Optional[_T]]: """ Returns a list of headers matching the given name as the raw string given. @@ -238,8 +242,8 @@ def getRawHeaders( values. Otherwise, C{default}. """ encodedName = self._encodeName(name) - values = self._rawHeaders.get(encodedName, None) - if values is None: + values = self._rawHeaders.get(encodedName, []) + if not values: return default if isinstance(name, str):