Skip to content

Commit 5e994de

Browse files
committed
style: fix non-pep604-annotation-union (UP007)
1 parent 3952b5d commit 5e994de

28 files changed

Lines changed: 86 additions & 86 deletions

httoop/authentication/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
import re
3-
from typing import Any, Dict, List, Tuple, Union
3+
from typing import Any, Dict, List, Tuple
44

55
from httoop.authentication.basic import BasicAuthRequestScheme, BasicAuthResponseScheme
66
from httoop.authentication.digest import DigestAuthRequestScheme, DigestAuthResponseScheme
@@ -22,7 +22,7 @@ def sanitize(self) -> None:
2222
self.params[key] = type(value)(x.encode('UTF-8') if not isinstance(x, bytes) and isinstance(x, str) else x for x in value)
2323

2424
@classmethod
25-
def parseparams(cls, elementstr: bytes) -> Union[Tuple[bytes, Dict[bytes, str]], Tuple[bytes, Dict[str, bytes]], Tuple[bytes, Dict[str, Union[bytes, List[bytes], bool]]], Tuple[bytes, Dict[str, Union[bytes, List[bytes]]]], Tuple[bytes, Dict[bytes, Union[str, bytes]]]]:
25+
def parseparams(cls, elementstr: bytes) -> Tuple[bytes, Dict[bytes, str]] | Tuple[bytes, Dict[str, bytes]] | Tuple[bytes, Dict[str, bytes | List[bytes] | bool]] | Tuple[bytes, Dict[str, bytes | List[bytes]]] | Tuple[bytes, Dict[bytes, str | bytes]]:
2626
try:
2727
scheme, authinfo = elementstr.split(b' ', 1)
2828
except ValueError:
@@ -53,7 +53,7 @@ def compose(self) -> bytes:
5353
return b'%s %s' % (self.value.encode('ASCII').title(), authinfo)
5454

5555
@classmethod
56-
def split(cls, value: bytes) -> List[Union[bytes, Any]]:
56+
def split(cls, value: bytes) -> List[bytes | Any]:
5757
value = cls.RE_SPACE_SPLIT.split(value)
5858
indexes = [i for i, val in enumerate(value) if val != b',' and b'=' not in val]
5959
return [b' '.join(value[a:b]) for a, b in zip(indexes, indexes[1:] + [None])]
@@ -99,7 +99,7 @@ class AuthResponseElement(AuthElement):
9999
}
100100

101101
@classmethod
102-
def sorted(cls, elements: List[Union[WWWAuthenticate, Any]]) -> List[Union[WWWAuthenticate, Any]]:
102+
def sorted(cls, elements: List[WWWAuthenticate | Any]) -> List[WWWAuthenticate | Any]:
103103
return list(sorted(elements, key=lambda e: {'basic': '\xff'}.get(e.value.lower(), e.value)))
104104

105105
@classmethod

httoop/authentication/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
from __future__ import annotations
33
from binascii import Error as Base64Error
4-
from typing import Dict, Union
4+
from typing import Dict
55

66
from httoop.exceptions import InvalidHeader
77
from httoop.header.element import HeaderElement
@@ -44,7 +44,7 @@ def compose(authinfo: ByteUnicodeDict) -> bytes:
4444
class BasicAuthResponseScheme:
4545

4646
@staticmethod
47-
def parse(authinfo: bytes) -> Dict[bytes, Union[str, bytes]]:
47+
def parse(authinfo: bytes) -> Dict[bytes, str | bytes]:
4848
params = HeaderElement.parseparams(b'X;%s' % authinfo)[1]
4949
params.setdefault(b'realm', b'')
5050
return params

httoop/authentication/digest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
from __future__ import annotations
33
from hashlib import md5, sha256
4-
from typing import Callable, Dict, List, Tuple, Union
4+
from typing import Callable, Dict, List, Tuple
55

66
from httoop.exceptions import InvalidHeader
77
from httoop.header.element import HeaderElement
@@ -21,7 +21,7 @@ class DigestAuthScheme:
2121
qops = (b'auth', b'auth-int') # quality of protection
2222

2323
@classmethod
24-
def get_algorithm(cls, algorithm: Union[bytes, str]) -> Callable:
24+
def get_algorithm(cls, algorithm: bytes | str) -> Callable:
2525
try:
2626
return cls.algorithms[algorithm.decode('ASCII', 'ignore') if isinstance(algorithm, bytes) else algorithm]
2727
except KeyError:
@@ -85,7 +85,7 @@ def _compose(cls, authinfo: ByteUnicodeDict) -> List[Tuple[str, bytes]]:
8585
return [(k, v) for k, v in params if v is not None]
8686

8787
@classmethod
88-
def parse(cls, authinfo: bytes) -> Dict[str, Union[bytes, List[bytes], bool]]:
88+
def parse(cls, authinfo: bytes) -> Dict[str, bytes | List[bytes] | bool]:
8989
params = super(cls, cls).parse(authinfo)
9090
if b'"' in params['nonce']:
9191
raise InvalidHeader(_('Nonce must not contain double quote'))

httoop/codecs/application/hal_json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, Dict, Iterator, List, Optional, Union
5+
from typing import Any, Dict, Iterator, List, Optional
66

77

88
try:
@@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs) -> None:
3636
def self(self) -> str:
3737
return self.expand(self.get_link('self')['href'])
3838

39-
def get_links(self, relation: str, name: None = None) -> Iterator[Dict[str, Union[None, bool, str]]]:
39+
def get_links(self, relation: str, name: None = None) -> Iterator[Dict[str, None | bool | str]]:
4040
links = self['_links'].get(relation)
4141
if links is None:
4242
return
@@ -66,7 +66,7 @@ def get_links(self, relation: str, name: None = None) -> Iterator[Dict[str, Unio
6666
link['deprecation'] = False
6767
yield link
6868

69-
def get_link(self, relation: str, name: Optional[str] = None) -> Optional[Dict[str, Optional[Union[bool, str]]]]:
69+
def get_link(self, relation: str, name: Optional[str] = None) -> Optional[Dict[str, Optional[bool | str]]]:
7070
try:
7171
return next(self.get_links(relation, name))
7272
except StopIteration:
@@ -128,7 +128,7 @@ def decode(cls, data: bytes, charset: Optional[str] = None, mimetype: Optional[C
128128
return Resource(data)
129129

130130
@classmethod
131-
def encode(cls, data: Union[Dict[str, None], Resource], charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> bytes:
131+
def encode(cls, data: Dict[str, None] | Resource, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> bytes:
132132
if not isinstance(data, dict):
133133
raise EncodeError('HAL documents must be JSON objects.')
134134

httoop/codecs/application/json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from json import dumps as json_encode, loads as json_decode
4-
from typing import Any, Dict, Optional, Union
4+
from typing import Any, Dict, Optional
55

66
from httoop.codecs.codec import Codec
77

@@ -10,7 +10,7 @@ class JSON(Codec):
1010
mimetype = 'application/json'
1111

1212
@classmethod
13-
def encode(cls, data: Union[Dict[str, str], Resource], charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> bytes:
13+
def encode(cls, data: Dict[str, str] | Resource, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> bytes:
1414
data = json_encode(data)
1515
if not isinstance(data, bytes): # python3
1616
data = data.encode(charset or 'UTF-8')

httoop/codecs/application/x_www_form_urlencoded.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FormURLEncoded(Codec):
1414
UNQUOTED = Percent.UNRESERVED
1515

1616
@classmethod
17-
def decode(cls, data: bytes, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> Union[Tuple[Tuple[str, str], Tuple[str, str]], Tuple[Tuple[str, str]], Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]], Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str], Tuple[str, str]], Tuple[()]]:
17+
def decode(cls, data: bytes, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> Tuple[Tuple[str, str], Tuple[str, str]] | Tuple[Tuple[str, str]] | Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]] | Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str], Tuple[str, str]] | Tuple[()]:
1818
if not data:
1919
return ()
2020
data = data.replace(b'+', b' ').strip(b'&').split(b'&')
@@ -36,6 +36,6 @@ def unquote(cls, data: bytes, charset: Optional[str] = None) -> str:
3636
return Percent.unquote(data).decode(charset or 'ISO8859-1')
3737

3838
@classmethod
39-
def quote(cls, data: Union[str, List[int]], charset: Optional[str] = None) -> bytes:
39+
def quote(cls, data: str | List[int], charset: Optional[str] = None) -> bytes:
4040
data = data.encode(charset or 'ISO8859-1')
4141
return Percent.quote(data, cls.UNQUOTED)

httoop/codecs/message/http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Optional, Union
3+
from typing import Optional
44

55
from httoop.codecs.codec import Codec
66

@@ -10,11 +10,11 @@ class HTTP(Codec):
1010
mimetype = 'message/http'
1111

1212
@classmethod
13-
def encode(cls, data: Union[Request, Response], charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> bytes:
13+
def encode(cls, data: Request | Response, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> bytes:
1414
return bytes(data) + bytes(data.headers) + bytes(data.body)
1515

1616
@classmethod
17-
def decode(cls, data: bytes, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> Union[Request, Response]:
17+
def decode(cls, data: bytes, charset: Optional[str] = None, mimetype: Optional[ContentType] = None) -> Request | Response:
1818
from httoop.messages import Request, Response
1919
line, data = data.split(b'\r\n', 1)
2020
message = Request()

httoop/date.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# import calendar
1313
from datetime import datetime
14-
from typing import Any, Optional, Union
14+
from typing import Any, Optional
1515

1616
from httoop.exceptions import InvalidDate
1717
from httoop.meta import HTTPSemantic
@@ -155,13 +155,13 @@ def __eq__(self, other: Any) -> bool:
155155
except NotImplementedError: # pragma: no cover
156156
return NotImplemented
157157

158-
def __gt__(self, other: Optional[Union[Date, str]]) -> bool:
158+
def __gt__(self, other: Optional[Date | str]) -> bool:
159159
try:
160160
return int(self) > int(self.__other(other))
161161
except NotImplementedError: # pragma: no cover
162162
return NotImplemented
163163

164-
def __lt__(self, other: Optional[Union[Date, str]]) -> bool:
164+
def __lt__(self, other: Optional[Date | str]) -> bool:
165165
try:
166166
return int(self) < int(self.__other(other))
167167
except NotImplementedError: # pragma: no cover

httoop/gateway/wsgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66
from __future__ import annotations
77

8-
from typing import Any, Callable, Dict, Iterator, Optional, Tuple, Union
8+
from typing import Any, Callable, Dict, Iterator, Optional, Tuple
99

1010
from httoop.messages import Body
1111
from httoop.six import PY2, reraise
@@ -119,7 +119,7 @@ def buffered(data):
119119
self.response.body = buffered(data)
120120
return raw_result
121121

122-
def get_environ(self) -> Dict[str, Optional[Union[str, Tuple[int, int], WSGIBody, bool]]]:
122+
def get_environ(self) -> Dict[str, Optional[str | Tuple[int, int] | WSGIBody | bool]]:
123123
environ = {}
124124
environ.update(dict(self.environ.items()))
125125
environ.update(dict([

httoop/header/element.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import re
1313
from binascii import b2a_base64
1414
from email.errors import HeaderParseError
15-
from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union
15+
from typing import Any, Dict, Iterator, List, Optional, Tuple, Type
1616

1717
from httoop.exceptions import InvalidHeader
1818
from httoop.six import with_metaclass
@@ -57,10 +57,10 @@ def __init__(self, value: str, params: Optional[Any] = None) -> None:
5757
def sanitize(self) -> None:
5858
pass
5959

60-
def __lt__(self, other: Union[str]) -> bool:
60+
def __lt__(self, other: str) -> bool:
6161
return self.value < getattr(other, 'value', other)
6262

63-
def __gt__(self, other: Union[str]) -> bool:
63+
def __gt__(self, other: str) -> bool:
6464
return self.value > getattr(other, 'value', other)
6565

6666
def __eq__(self, other: Any) -> bool:
@@ -86,7 +86,7 @@ def compose(self) -> bytes:
8686
return b'%s%s' % (self.encode_rfc2047(self.value), b''.join(params))
8787

8888
@classmethod
89-
def parseparams(cls, elementstr: bytes) -> Union[Tuple[bytes, Dict[bytes, str]], Tuple[bytes, Dict[Any, Any]]]:
89+
def parseparams(cls, elementstr: bytes) -> Tuple[bytes, Dict[bytes, str]] | Tuple[bytes, Dict[Any, Any]]:
9090
"""Transform 'token;key=val' to ('token', {'key': 'val'})."""
9191
# Split the element into a value and parameters. The 'value' may
9292
# be of the form, "token=token", but we don't split that here.
@@ -200,7 +200,7 @@ def merge(cls, elements: List, others: List) -> bytes:
200200
return cls.join([bytes(x) for x in cls.sorted(elements + others)])
201201

202202
@classmethod
203-
def formatparam(cls, param: bytes, value: Optional[Union[bytes, str]] = None, quote: bool = False) -> bytes:
203+
def formatparam(cls, param: bytes, value: Optional[bytes | str] = None, quote: bool = False) -> bytes:
204204
"""
205205
Convenience function to format and return a key=value pair.
206206
@@ -367,7 +367,7 @@ def __eq__(self, other: str) -> bool:
367367
other = _AcceptElement(other)
368368
return other.value == self.value and other.quality == self.quality
369369

370-
def __lt__(self, other: Union[str]) -> bool:
370+
def __lt__(self, other: str) -> bool:
371371
if not isinstance(other, _AcceptElement):
372372
other = _AcceptElement(other)
373373
if self.quality == other.quality:

0 commit comments

Comments
 (0)