Skip to content

Commit 7676d50

Browse files
committed
🧪 Integrate flake8-typing-as-t into linting
The `_t` imported name has been chosen to ensure `typing` isn't exposed as a public importable in every module.
1 parent ae94832 commit 7676d50

File tree

13 files changed

+147
-126
lines changed

13 files changed

+147
-126
lines changed

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ per-file-ignores =
106106
# WPS226 Found string literal over-use: %s%s> %s > 3
107107
toxfile.py: WPS202, WPS226
108108

109+
# NOTE: Python stub files don't need most of the linting checks, only
110+
# NOTE: `flake8-typing-as-t` is important.
111+
# FIXME: Re-enable some checks gradually.
112+
**/**.pyi: E, LN, WPS
113+
109114
# There are multiple `assert`s (S101)
110115
# and subprocesses (import – S404; call – S603) in tests:
111116
cheroot/test/test_*.py: S101, S404, S603
@@ -169,6 +174,10 @@ pytest-parametrize-values-row-type = tuple
169174
# PT023:
170175
pytest-mark-no-parentheses = true
171176

177+
# flake8-typing-as-t
178+
# TYT02:
179+
typing-as-t-imported-name = _t
180+
172181
# wemake-python-styleguide
173182
show-source = true
174183
show-violation-links = true

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ repos:
187187
- flake8-logging-format ~= 2024.24.12
188188
- flake8-pytest-style ~= 2.2.0
189189
- flake8-spellcheck ~= 0.28.0
190+
- flake8-typing-as-t ~= 1.1.0
190191
- wemake-python-styleguide ~= 1.4.0
192+
types: []
193+
types_or:
194+
- python
195+
- pyi
191196

192197
# `flake8-logging-format` is incompatible with Python 3.12+
193198
# * https://github.com/globality-corp/flake8-logging-format/issues/80

cheroot/_compat.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from typing import ContextManager, Optional, Type, Union
1+
import typing as _t
22

3-
def suppress(*exceptions: Type[BaseException]) -> ContextManager[None]: ...
3+
def suppress(
4+
*exceptions: _t.Type[BaseException],
5+
) -> _t.ContextManager[None]: ...
46

5-
IS_ABOVE_OPENSSL10: Optional[bool]
6-
IS_ABOVE_OPENSSL31: Union[bool, None]
7+
IS_ABOVE_OPENSSL10: bool | None
8+
IS_ABOVE_OPENSSL31: bool | None
79
IS_CI: bool
810
IS_GITHUB_ACTIONS_WORKFLOW: bool
911
IS_PYPY: bool
@@ -19,4 +21,4 @@ def ntob(n: str, encoding: str = ...) -> bytes: ...
1921
def ntou(n: str, encoding: str = ...) -> str: ...
2022
def bton(b: bytes, encoding: str = ...) -> str: ...
2123
def assert_native(n: str) -> None: ...
22-
def extract_bytes(mv: Union[memoryview, bytes]) -> bytes: ...
24+
def extract_bytes(mv: memoryview | bytes) -> bytes: ...

cheroot/cli.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
from typing import Any
1+
import typing as _t
22

33
class BindLocation: ...
44

55
class TCPSocket(BindLocation):
6-
bind_addr: Any
6+
bind_addr: _t.Any
77
def __init__(self, address, port) -> None: ...
88

99
class UnixSocket(BindLocation):
10-
bind_addr: Any
10+
bind_addr: _t.Any
1111
def __init__(self, path) -> None: ...
1212

1313
class AbstractSocket(BindLocation):
14-
bind_addr: Any
14+
bind_addr: _t.Any
1515
def __init__(self, abstract_socket) -> None: ...
1616

1717
class Application:
1818
@classmethod
1919
def resolve(cls, full_path): ...
20-
wsgi_app: Any
20+
wsgi_app: _t.Any
2121
def __init__(self, wsgi_app) -> None: ...
2222
def server_args(self, parsed_args): ...
2323
def server(self, parsed_args): ...
2424

2525
class GatewayYo:
26-
gateway: Any
26+
gateway: _t.Any
2727
def __init__(self, gateway) -> None: ...
2828
def server(self, parsed_args): ...
2929

cheroot/connections.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
import typing as _t
22

33
IS_WINDOWS: bool
44

@@ -9,13 +9,13 @@ class _ThreadsafeSelector:
99
def __len__(self): ...
1010
@property
1111
def connections(self) -> None: ...
12-
def register(self, fileobj, events, data: Any | None = ...): ...
12+
def register(self, fileobj, events, data: _t.Any | None = ...): ...
1313
def unregister(self, fileobj): ...
14-
def select(self, timeout: Any | None = ...): ...
14+
def select(self, timeout: _t.Any | None = ...): ...
1515
def close(self) -> None: ...
1616

1717
class ConnectionManager:
18-
server: Any
18+
server: _t.Any
1919
def __init__(self, server) -> None: ...
2020
def put(self, conn) -> None: ...
2121
def stop(self) -> None: ...

cheroot/errors.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from typing import List, Set, Tuple, Type
1+
import typing as _t
22

33
class MaxSizeExceeded(Exception): ...
44
class NoSSLError(Exception): ...
55
class FatalSSLAlert(Exception): ...
66

7-
def plat_specific_errors(*errnames: str) -> List[int]: ...
7+
def plat_specific_errors(*errnames: str) -> list[int]: ...
88

9-
socket_error_eintr: List[int]
10-
socket_errors_to_ignore: List[int]
11-
socket_errors_nonblocking: List[int]
12-
acceptable_sock_shutdown_error_codes: Set[int]
13-
acceptable_sock_shutdown_exceptions: Tuple[Type[Exception], ...]
9+
socket_error_eintr: list[int]
10+
socket_errors_to_ignore: list[int]
11+
socket_errors_nonblocking: list[int]
12+
acceptable_sock_shutdown_error_codes: set[int]
13+
acceptable_sock_shutdown_exceptions: tuple[_t.Type[Exception], ...]

cheroot/server.pyi

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
import typing as _t
22

33
__all__ = (
44
'ChunkedRFile',
@@ -14,81 +14,81 @@ __all__ = (
1414
)
1515

1616
class HeaderReader:
17-
def __call__(self, rfile, hdict: Any | None = ...): ...
17+
def __call__(self, rfile, hdict: _t.Any | None = ...): ...
1818

1919
class DropUnderscoreHeaderReader(HeaderReader): ...
2020

2121
class SizeCheckWrapper:
22-
rfile: Any
23-
maxlen: Any
22+
rfile: _t.Any
23+
maxlen: _t.Any
2424
bytes_read: int
2525
def __init__(self, rfile, maxlen) -> None: ...
26-
def read(self, size: Any | None = ...): ...
27-
def readline(self, size: Any | None = ...): ...
26+
def read(self, size: _t.Any | None = ...): ...
27+
def readline(self, size: _t.Any | None = ...): ...
2828
def readlines(self, sizehint: int = ...): ...
2929
def close(self) -> None: ...
3030
def __iter__(self): ...
3131
def __next__(self): ...
32-
next: Any
32+
next: _t.Any
3333

3434
class KnownLengthRFile:
35-
rfile: Any
36-
remaining: Any
35+
rfile: _t.Any
36+
remaining: _t.Any
3737
def __init__(self, rfile, content_length) -> None: ...
38-
def read(self, size: Any | None = ...): ...
39-
def readline(self, size: Any | None = ...): ...
38+
def read(self, size: _t.Any | None = ...): ...
39+
def readline(self, size: _t.Any | None = ...): ...
4040
def readlines(self, sizehint: int = ...): ...
4141
def close(self) -> None: ...
4242
def __iter__(self): ...
4343
def __next__(self): ...
44-
next: Any
44+
next: _t.Any
4545

4646
class ChunkedRFile:
47-
rfile: Any
48-
maxlen: Any
47+
rfile: _t.Any
48+
maxlen: _t.Any
4949
bytes_read: int
50-
buffer: Any
51-
bufsize: Any
50+
buffer: _t.Any
51+
bufsize: _t.Any
5252
closed: bool
5353
def __init__(self, rfile, maxlen, bufsize: int = ...) -> None: ...
54-
def read(self, size: Any | None = ...): ...
55-
def readline(self, size: Any | None = ...): ...
54+
def read(self, size: _t.Any | None = ...): ...
55+
def readline(self, size: _t.Any | None = ...): ...
5656
def readlines(self, sizehint: int = ...): ...
5757
def read_trailer_lines(self) -> None: ...
5858
def close(self) -> None: ...
5959

6060
class HTTPRequest:
61-
server: Any
62-
conn: Any
63-
inheaders: Any
64-
outheaders: Any
61+
server: _t.Any
62+
conn: _t.Any
63+
inheaders: _t.Any
64+
outheaders: _t.Any
6565
ready: bool
6666
close_connection: bool
6767
chunked_write: bool
68-
header_reader: Any
68+
header_reader: _t.Any
6969
started_request: bool
7070
scheme: bytes
7171
response_protocol: str
7272
status: str
7373
sent_headers: bool
7474
chunked_read: bool
75-
proxy_mode: Any
76-
strict_mode: Any
75+
proxy_mode: _t.Any
76+
strict_mode: _t.Any
7777
def __init__(
7878
self,
7979
server,
8080
conn,
8181
proxy_mode: bool = ...,
8282
strict_mode: bool = ...,
8383
) -> None: ...
84-
rfile: Any
84+
rfile: _t.Any
8585
def parse_request(self) -> None: ...
86-
uri: Any
87-
method: Any
88-
authority: Any
89-
path: Any
90-
qs: Any
91-
request_protocol: Any
86+
uri: _t.Any
87+
method: _t.Any
88+
authority: _t.Any
89+
path: _t.Any
90+
qs: _t.Any
91+
request_protocol: _t.Any
9292
def read_request_line(self): ...
9393
def read_request_headers(self): ...
9494
def respond(self) -> None: ...
@@ -98,19 +98,19 @@ class HTTPRequest:
9898
def send_headers(self) -> None: ...
9999

100100
class HTTPConnection:
101-
remote_addr: Any
102-
remote_port: Any
103-
ssl_env: Any
104-
rbufsize: Any
105-
wbufsize: Any
106-
RequestHandlerClass: Any
101+
remote_addr: _t.Any
102+
remote_port: _t.Any
103+
ssl_env: _t.Any
104+
rbufsize: _t.Any
105+
wbufsize: _t.Any
106+
RequestHandlerClass: _t.Any
107107
peercreds_enabled: bool
108108
peercreds_resolve_enabled: bool
109-
last_used: Any
110-
server: Any
111-
socket: Any
112-
rfile: Any
113-
wfile: Any
109+
last_used: _t.Any
110+
server: _t.Any
111+
socket: _t.Any
112+
rfile: _t.Any
113+
wfile: _t.Any
114114
requests_seen: int
115115
def __init__(self, server, sock, makefile=...) -> None: ...
116116
def communicate(self): ...
@@ -130,48 +130,48 @@ class HTTPConnection:
130130
def peer_group(self): ...
131131

132132
class HTTPServer:
133-
gateway: Any
134-
minthreads: Any
135-
maxthreads: Any
136-
server_name: Any
133+
gateway: _t.Any
134+
minthreads: _t.Any
135+
maxthreads: _t.Any
136+
server_name: _t.Any
137137
protocol: str
138138
request_queue_size: int
139139
shutdown_timeout: int
140140
timeout: int
141141
expiration_interval: float
142-
version: Any
143-
software: Any
142+
version: _t.Any
143+
software: _t.Any
144144
ready: bool
145145
max_request_header_size: int
146146
max_request_body_size: int
147147
nodelay: bool
148-
ConnectionClass: Any
149-
ssl_adapter: Any
148+
ConnectionClass: _t.Any
149+
ssl_adapter: _t.Any
150150
peercreds_enabled: bool
151151
peercreds_resolve_enabled: bool
152152
reuse_port: bool
153153
keep_alive_conn_limit: int
154-
requests: Any
154+
requests: _t.Any
155155
def __init__(
156156
self,
157157
bind_addr,
158158
gateway,
159159
minthreads: int = ...,
160160
maxthreads: int = ...,
161-
server_name: Any | None = ...,
161+
server_name: _t.Any | None = ...,
162162
peercreds_enabled: bool = ...,
163163
peercreds_resolve_enabled: bool = ...,
164164
reuse_port: bool = ...,
165165
) -> None: ...
166-
stats: Any
166+
stats: _t.Any
167167
def clear_stats(self): ...
168168
def runtime(self): ...
169169
@property
170170
def bind_addr(self): ...
171171
@bind_addr.setter
172172
def bind_addr(self, value) -> None: ...
173173
def safe_start(self) -> None: ...
174-
socket: Any
174+
socket: _t.Any
175175
def prepare(self) -> None: ...
176176
def serve(self) -> None: ...
177177
def start(self) -> None: ...
@@ -211,7 +211,7 @@ class HTTPServer:
211211
def stop(self) -> None: ...
212212

213213
class Gateway:
214-
req: Any
214+
req: _t.Any
215215
def __init__(self, req) -> None: ...
216216
def respond(self) -> None: ...
217217

cheroot/ssl/__init__.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
import typing as _t
12
from abc import ABC, abstractmethod
2-
from typing import Any
33

44
class Adapter(ABC):
5-
certificate: Any
6-
private_key: Any
7-
certificate_chain: Any
8-
ciphers: Any
5+
certificate: _t.Any
6+
private_key: _t.Any
7+
certificate_chain: _t.Any
8+
ciphers: _t.Any
99
private_key_password: str | bytes | None
10-
context: Any
10+
context: _t.Any
1111
@abstractmethod
1212
def __init__(
1313
self,
1414
certificate,
1515
private_key,
16-
certificate_chain: Any | None = ...,
17-
ciphers: Any | None = ...,
16+
certificate_chain: _t.Any | None = ...,
17+
ciphers: _t.Any | None = ...,
1818
*,
1919
private_key_password: str | bytes | None = ...,
2020
): ...

0 commit comments

Comments
 (0)