Skip to content

Commit ff5c23f

Browse files
committed
style: fix non-pep585-annotation (UP006)
1 parent a06befd commit ff5c23f

37 files changed

Lines changed: 110 additions & 114 deletions

httoop/authentication/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
2+
23
import re
3-
from typing import Any, Dict, List, Tuple
4+
from typing import Any
45

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

2425
@classmethod
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]]:
26+
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]]:
2627
try:
2728
scheme, authinfo = elementstr.split(b' ', 1)
2829
except ValueError:
@@ -53,7 +54,7 @@ def compose(self) -> bytes:
5354
return b'%s %s' % (self.value.encode('ASCII').title(), authinfo)
5455

5556
@classmethod
56-
def split(cls, value: bytes) -> List[bytes | Any]:
57+
def split(cls, value: bytes) -> list[bytes | Any]:
5758
value = cls.RE_SPACE_SPLIT.split(value)
5859
indexes = [i for i, val in enumerate(value) if val != b',' and b'=' not in val]
5960
return [b' '.join(value[a:b]) for a, b in zip(indexes, indexes[1:] + [None])]
@@ -99,11 +100,11 @@ class AuthResponseElement(AuthElement):
99100
}
100101

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

105106
@classmethod
106-
def join(cls, values: List[bytes]) -> bytes:
107+
def join(cls, values: list[bytes]) -> bytes:
107108
return b' '.join(values)
108109

109110
@property

httoop/authentication/basic.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
3+
34
from binascii import Error as Base64Error
4-
from typing import Dict
55

66
from httoop.exceptions import InvalidHeader
77
from httoop.header.element import HeaderElement
@@ -11,7 +11,7 @@
1111
class BasicAuthRequestScheme:
1212

1313
@staticmethod
14-
def parse(authinfo: bytes) -> Dict[str, bytes]:
14+
def parse(authinfo: bytes) -> dict[str, bytes]:
1515
# try:
1616
# authinfo = authinfo.encode('ascii')
1717
# except ValueError:
@@ -44,7 +44,7 @@ def compose(authinfo: ByteUnicodeDict) -> bytes:
4444
class BasicAuthResponseScheme:
4545

4646
@staticmethod
47-
def parse(authinfo: bytes) -> Dict[bytes, 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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
from __future__ import annotations
3+
34
from hashlib import md5, sha256
4-
from typing import Callable, Dict, List, Tuple
5+
from typing import Callable
56

67
from httoop.exceptions import InvalidHeader
78
from httoop.header.element import HeaderElement
@@ -56,7 +57,7 @@ def parse(cls, authinfo: bytes) -> ByteUnicodeDict:
5657
class DigestAuthResponseScheme(DigestAuthScheme): # WWW-Authenticate
5758

5859
@classmethod
59-
def _compose(cls, authinfo: ByteUnicodeDict) -> List[Tuple[str, bytes]]:
60+
def _compose(cls, authinfo: ByteUnicodeDict) -> list[tuple[str, bytes]]:
6061
realm = authinfo['realm']
6162
algorithm = authinfo.get('algorithm', b'MD5')
6263
domain = authinfo.get('domain')
@@ -85,7 +86,7 @@ def _compose(cls, authinfo: ByteUnicodeDict) -> List[Tuple[str, bytes]]:
8586
return [(k, v) for k, v in params if v is not None]
8687

8788
@classmethod
88-
def parse(cls, authinfo: bytes) -> Dict[str, bytes | List[bytes] | bool]:
89+
def parse(cls, authinfo: bytes) -> dict[str, bytes | list[bytes] | bool]:
8990
params = super(cls, cls).parse(authinfo)
9091
if b'"' in params['nonce']:
9192
raise InvalidHeader(_('Nonce must not contain double quote'))
@@ -107,7 +108,7 @@ def parse(cls, authinfo: bytes) -> Dict[str, bytes | List[bytes] | bool]:
107108
class DigestAuthRequestScheme(DigestAuthScheme): # Authorization
108109

109110
@classmethod
110-
def _compose(cls, authinfo: ByteUnicodeDict) -> List[Tuple[str, bytes]]:
111+
def _compose(cls, authinfo: ByteUnicodeDict) -> list[tuple[str, bytes]]:
111112
username = authinfo['username']
112113
realm = authinfo['realm']
113114
digest_uri = authinfo['uri']
@@ -136,7 +137,7 @@ def _compose(cls, authinfo: ByteUnicodeDict) -> List[Tuple[str, bytes]]:
136137
return [(k, v) for k, v in params if v is not None]
137138

138139
@classmethod
139-
def parse(cls, authinfo: bytes) -> Dict[str, bytes]:
140+
def parse(cls, authinfo: bytes) -> dict[str, bytes]:
140141
params = super(cls, cls).parse(authinfo)
141142
message_qop = params.get('qop')
142143
cnonce = None

httoop/codecs/__init__.py

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

77
import inspect
8-
from typing import Any, Type
8+
from typing import Any
99

1010
from httoop.codecs import application, audio, example, image, message, model, multipart, text, video
1111
from httoop.codecs.codec import Codec
@@ -26,7 +26,7 @@ def lookup(encoding: str, raise_errors: bool = True) -> Any:
2626
return CODECS.get(encoding) or CODECS.get(type_) or (raise_errors and CODECS[encoding]) or None
2727

2828

29-
def register(encoding: str, codec: Type[Codec]) -> None:
29+
def register(encoding: str, codec: type[Codec]) -> None:
3030
CODECS[encoding] = codec
3131

3232

httoop/codecs/application/hal_json.py

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

33
from __future__ import annotations
44

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

77

88
try:
99
from uritemplate import expand
1010
except ImportError:
1111
# TODO: emit a warning
12-
def expand(href: str, templates: Dict[str, str]) -> str:
12+
def expand(href: str, templates: dict[str, str]) -> str:
1313
for templ, value in templates.items():
1414
href = href.replace('{%s}' % (templ, ), value)
1515
return href
@@ -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, 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,13 +66,13 @@ def get_links(self, relation: str, name: None = None) -> Iterator[Dict[str, None
6666
link['deprecation'] = False
6767
yield link
6868

69-
def get_link(self, relation: str, name: str | None = None) -> Dict[str, bool | str | None] | None:
69+
def get_link(self, relation: str, name: str | None = None) -> dict[str, bool | str | None] | None:
7070
try:
7171
return next(self.get_links(relation, name))
7272
except StopIteration:
7373
pass
7474

75-
def get_relations(self) -> List[str]:
75+
def get_relations(self) -> list[str]:
7676
return list(set(self['_links'].keys()) | set(self['_embedded'].keys()))
7777

7878
def get_resources(self, relation: str) -> None:
@@ -103,15 +103,15 @@ def get_curie(self, relation: str) -> str:
103103
return self.expand(link['href'], rel=rel)
104104
return relation
105105

106-
def add_link(self, relation: str, link: Dict[str, str]) -> None:
106+
def add_link(self, relation: str, link: dict[str, str]) -> None:
107107
links = self['_links'].setdefault(relation, [])
108108
if not isinstance(links, list):
109109
links = [links]
110110
links.append(link)
111111
self['_links'][relation] = links
112112
self['_links'][relation] = list(self.get_links(relation))
113113

114-
def add_resource(self, relation: str, resource: Dict[Any, Any]) -> None:
114+
def add_resource(self, relation: str, resource: dict[Any, Any]) -> None:
115115
resources = list(self.get_resources(relation))
116116
resources.append(resource)
117117
self['_embedded'][relation] = resources
@@ -128,7 +128,7 @@ def decode(cls, data: bytes, charset: str | None = None, mimetype: ContentType |
128128
return Resource(data)
129129

130130
@classmethod
131-
def encode(cls, data: Dict[str, None] | Resource, charset: str | None = None, mimetype: ContentType | None = None) -> bytes:
131+
def encode(cls, data: dict[str, None] | Resource, charset: str | None = None, mimetype: ContentType | None = 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: 3 additions & 3 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
4+
from typing import Any
55

66
from httoop.codecs.codec import Codec
77

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

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

1919
@classmethod
20-
def decode(cls, data: bytes, charset: str | None = None, mimetype: ContentType | None = None) -> Dict[str, Any]:
20+
def decode(cls, data: bytes, charset: str | None = None, mimetype: ContentType | None = None) -> dict[str, Any]:
2121
return json_decode(data.decode(charset or 'ASCII'))

httoop/codecs/application/x_www_form_urlencoded.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
2-
from typing import Any, List, Optional, Tuple, Union
2+
3+
from typing import Any
34

45
from httoop.codecs.codec import Codec
56
from httoop.uri.percent_encoding import Percent
@@ -14,7 +15,7 @@ class FormURLEncoded(Codec):
1415
UNQUOTED = Percent.UNRESERVED
1516

1617
@classmethod
17-
def decode(cls, data: bytes, charset: str | None = None, mimetype: ContentType | None = 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[()]:
18+
def decode(cls, data: bytes, charset: str | None = None, mimetype: ContentType | None = 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[()]:
1819
if not data:
1920
return ()
2021
data = data.replace(b'+', b' ').strip(b'&').split(b'&')
@@ -36,6 +37,6 @@ def unquote(cls, data: bytes, charset: str | None = None) -> str:
3637
return Percent.unquote(data).decode(charset or 'ISO8859-1')
3738

3839
@classmethod
39-
def quote(cls, data: str | List[int], charset: str | None = None) -> bytes:
40+
def quote(cls, data: str | list[int], charset: str | None = None) -> bytes:
4041
data = data.encode(charset or 'ISO8859-1')
4142
return Percent.quote(data, cls.UNQUOTED)

httoop/codecs/application/xml.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def fromstring(data):
1919
raise ParseError('Will not parse without defusedxml!')
2020

2121

22-
from typing import Optional
2322

2423
from httoop.codecs.codec import Codec
2524
from httoop.exceptions import DecodeError

httoop/codecs/application/zlib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
import zlib
5-
from typing import Optional
65

76
from httoop.codecs.codec import Codec
87
from httoop.exceptions import DecodeError, EncodeError

httoop/codecs/message/http.py

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

3-
from typing import Optional
4-
53
from httoop.codecs.codec import Codec
64

75

0 commit comments

Comments
 (0)