Skip to content

Commit 3f5a608

Browse files
committed
linting++
1 parent 01c080a commit 3f5a608

12 files changed

+777
-717
lines changed

Diff for: pyproject.toml

+47-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,54 @@ h2 = [ "py.typed" ]
9191
version = { attr = "h2.__version__" }
9292

9393
[tool.ruff]
94-
line-length = 140
94+
line-length = 150
9595
target-version = "py39"
96+
format.preview = true
97+
format.docstring-code-line-length = 100
98+
format.docstring-code-format = true
99+
lint.select = [
100+
"ALL",
101+
]
102+
lint.ignore = [
103+
"PYI034", # PEP 673 not yet available in Python 3.9 - only in 3.11+
104+
"ANN001", # args with typing.Any
105+
"ANN002", # args with typing.Any
106+
"ANN003", # kwargs with typing.Any
107+
"ANN401", # kwargs with typing.Any
108+
"SLF001", # implementation detail
109+
"CPY", # not required
110+
"D101", # docs readability
111+
"D102", # docs readability
112+
"D105", # docs readability
113+
"D107", # docs readability
114+
"D200", # docs readability
115+
"D205", # docs readability
116+
"D205", # docs readability
117+
"D203", # docs readability
118+
"D212", # docs readability
119+
"D400", # docs readability
120+
"D401", # docs readability
121+
"D415", # docs readability
122+
"PLR2004", # readability
123+
"SIM108", # readability
124+
"RUF012", # readability
125+
"FBT001", # readability
126+
"FBT002", # readability
127+
"PGH003", # readability
128+
"PGH004", # readability
129+
"FIX001", # readability
130+
"FIX002", # readability
131+
"TD001", # readability
132+
"TD002", # readability
133+
"TD003", # readability
134+
"S101", # readability
135+
"PD901", # readability
136+
"ERA001", # readability
137+
"ARG001", # readability
138+
"ARG002", # readability
139+
"PLR0913", # readability
140+
]
141+
lint.isort.required-imports = [ "from __future__ import annotations" ]
96142

97143
[tool.mypy]
98144
show_error_codes = true

Diff for: src/h2/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
55
A HTTP/2 implementation.
66
"""
7-
__version__ = '4.1.0'
7+
from __future__ import annotations
8+
9+
__version__ = "4.1.0"

Diff for: src/h2/config.py

+26-20
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@
44
55
Objects for controlling the configuration of the HTTP/2 stack.
66
"""
7+
from __future__ import annotations
78

89
import sys
9-
from typing import Any, Optional, Union
10+
from typing import Any
1011

1112

1213
class _BooleanConfigOption:
1314
"""
1415
Descriptor for handling a boolean config option. This will block
1516
attempts to set boolean config options to non-bools.
1617
"""
18+
1719
def __init__(self, name: str) -> None:
1820
self.name = name
19-
self.attr_name = '_%s' % self.name
21+
self.attr_name = f"_{self.name}"
2022

2123
def __get__(self, instance: Any, owner: Any) -> bool:
2224
return getattr(instance, self.attr_name) # type: ignore
2325

2426
def __set__(self, instance: Any, value: bool) -> None:
2527
if not isinstance(value, bool):
26-
raise ValueError("%s must be a bool" % self.name)
28+
msg = f"{self.name} must be a bool"
29+
raise ValueError(msg) # noqa: TRY004
2730
setattr(instance, self.attr_name, value)
2831

2932

@@ -35,20 +38,19 @@ class DummyLogger:
3538
conditionals being sprinkled throughout the h2 code for calls to
3639
logging functions when no logger is passed into the corresponding object.
3740
"""
41+
3842
def __init__(self, *vargs) -> None: # type: ignore
3943
pass
4044

4145
def debug(self, *vargs, **kwargs) -> None: # type: ignore
4246
"""
4347
No-op logging. Only level needed for now.
4448
"""
45-
pass
4649

4750
def trace(self, *vargs, **kwargs) -> None: # type: ignore
4851
"""
4952
No-op logging. Only level needed for now.
5053
"""
51-
pass
5254

5355

5456
class OutputLogger:
@@ -61,15 +63,16 @@ class OutputLogger:
6163
Defaults to ``sys.stderr``.
6264
:param trace: Enables trace-level output. Defaults to ``False``.
6365
"""
64-
def __init__(self, file=None, trace_level=False): # type: ignore
66+
67+
def __init__(self, file=None, trace_level=False) -> None: # type: ignore
6568
super().__init__()
6669
self.file = file or sys.stderr
6770
self.trace_level = trace_level
6871

69-
def debug(self, fmtstr, *args): # type: ignore
72+
def debug(self, fmtstr, *args) -> None: # type: ignore
7073
print(f"h2 (debug): {fmtstr % args}", file=self.file)
7174

72-
def trace(self, fmtstr, *args): # type: ignore
75+
def trace(self, fmtstr, *args) -> None: # type: ignore
7376
if self.trace_level:
7477
print(f"h2 (trace): {fmtstr % args}", file=self.file)
7578

@@ -147,32 +150,33 @@ class H2Configuration:
147150
148151
:type logger: ``logging.Logger``
149152
"""
150-
client_side = _BooleanConfigOption('client_side')
153+
154+
client_side = _BooleanConfigOption("client_side")
151155
validate_outbound_headers = _BooleanConfigOption(
152-
'validate_outbound_headers'
156+
"validate_outbound_headers",
153157
)
154158
normalize_outbound_headers = _BooleanConfigOption(
155-
'normalize_outbound_headers'
159+
"normalize_outbound_headers",
156160
)
157161
split_outbound_cookies = _BooleanConfigOption(
158-
'split_outbound_cookies'
162+
"split_outbound_cookies",
159163
)
160164
validate_inbound_headers = _BooleanConfigOption(
161-
'validate_inbound_headers'
165+
"validate_inbound_headers",
162166
)
163167
normalize_inbound_headers = _BooleanConfigOption(
164-
'normalize_inbound_headers'
168+
"normalize_inbound_headers",
165169
)
166170

167171
def __init__(self,
168172
client_side: bool = True,
169-
header_encoding: Optional[Union[bool, str]] = None,
173+
header_encoding: bool | str | None = None,
170174
validate_outbound_headers: bool = True,
171175
normalize_outbound_headers: bool = True,
172176
split_outbound_cookies: bool = False,
173177
validate_inbound_headers: bool = True,
174178
normalize_inbound_headers: bool = True,
175-
logger: Optional[Union[DummyLogger, OutputLogger]] = None) -> None:
179+
logger: DummyLogger | OutputLogger | None = None) -> None:
176180
self.client_side = client_side
177181
self.header_encoding = header_encoding
178182
self.validate_outbound_headers = validate_outbound_headers
@@ -183,7 +187,7 @@ def __init__(self,
183187
self.logger = logger or DummyLogger(__name__)
184188

185189
@property
186-
def header_encoding(self) -> Optional[Union[bool, str]]:
190+
def header_encoding(self) -> bool | str | None:
187191
"""
188192
Controls whether the headers emitted by this object in events are
189193
transparently decoded to ``unicode`` strings, and what encoding is used
@@ -195,12 +199,14 @@ def header_encoding(self) -> Optional[Union[bool, str]]:
195199
return self._header_encoding
196200

197201
@header_encoding.setter
198-
def header_encoding(self, value: Optional[Union[bool, str]]) -> None:
202+
def header_encoding(self, value: bool | str | None) -> None:
199203
"""
200204
Enforces constraints on the value of header encoding.
201205
"""
202206
if not isinstance(value, (bool, str, type(None))):
203-
raise ValueError("header_encoding must be bool, string, or None")
207+
msg = "header_encoding must be bool, string, or None"
208+
raise ValueError(msg) # noqa: TRY004
204209
if value is True:
205-
raise ValueError("header_encoding cannot be True")
210+
msg = "header_encoding cannot be True"
211+
raise ValueError(msg)
206212
self._header_encoding = value

0 commit comments

Comments
 (0)