Skip to content

Commit 903fdb5

Browse files
committed
lint++
1 parent 2595cf6 commit 903fdb5

File tree

8 files changed

+216
-225
lines changed

8 files changed

+216
-225
lines changed

docs/source/_static/.keep

Whitespace-only changes.

pyproject.toml

+35-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,41 @@ ignore = [
9292
]
9393

9494
[tool.ruff]
95-
line-length = 140
95+
line-length = 150
9696
target-version = "py39"
97+
format.preview = true
98+
format.docstring-code-line-length = 100
99+
format.docstring-code-format = true
100+
lint.select = [
101+
"ALL",
102+
]
103+
lint.ignore = [
104+
"ANN401", # kwargs with typing.Any
105+
"CPY", # not required
106+
"D101", # docs readability
107+
"D102", # docs readability
108+
"D105", # docs readability
109+
"D107", # docs readability
110+
"D200", # docs readability
111+
"D205", # docs readability
112+
"D205", # docs readability
113+
"D203", # docs readability
114+
"D212", # docs readability
115+
"D400", # docs readability
116+
"D401", # docs readability
117+
"D415", # docs readability
118+
"PLR2004", # readability
119+
"SIM108", # readability
120+
"RUF012", # readability
121+
"FBT001", # readability
122+
"FBT002", # readability
123+
"PGH003", # readability
124+
]
125+
lint.isort.required-imports = [ "from __future__ import annotations" ]
126+
127+
[tool.mypy]
128+
show_error_codes = true
129+
strict = true
97130

98131
[tool.coverage.run]
99132
branch = true
@@ -104,7 +137,7 @@ fail_under = 100
104137
show_missing = true
105138
exclude_lines = [
106139
"pragma: no cover",
107-
"raise NotImplementedError()",
140+
"raise NotImplementedError",
108141
]
109142

110143
[tool.coverage.paths]

src/hyperframe/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
2-
hyperframe
3-
~~~~~~~~~~
4-
5-
A module for providing a pure-Python HTTP/2 framing layer.
2+
Provides a pure-Python HTTP/2 framing layer.
63
"""
7-
__version__ = '6.1.0+dev'
4+
from __future__ import annotations
5+
6+
__version__ = "6.1.0+dev"

src/hyperframe/exceptions.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""
2-
hyperframe/exceptions
3-
~~~~~~~~~~~~~~~~~~~~~
4-
5-
Defines the exceptions that can be thrown by hyperframe.
2+
Exceptions that can be thrown by hyperframe.
63
"""
4+
from __future__ import annotations
75

86

97
class HyperframeError(Exception):
@@ -21,6 +19,7 @@ class UnknownFrameError(HyperframeError):
2119
.. versionchanged:: 6.0.0
2220
Changed base class from `ValueError` to :class:`HyperframeError`
2321
"""
22+
2423
def __init__(self, frame_type: int, length: int) -> None:
2524
#: The type byte of the unknown frame that was received.
2625
self.frame_type = frame_type
@@ -30,8 +29,7 @@ def __init__(self, frame_type: int, length: int) -> None:
3029

3130
def __str__(self) -> str:
3231
return (
33-
"UnknownFrameError: Unknown frame type 0x%X received, "
34-
"length %d bytes" % (self.frame_type, self.length)
32+
f"UnknownFrameError: Unknown frame type 0x{self.frame_type:X} received, length {self.length} bytes"
3533
)
3634

3735

@@ -42,7 +40,6 @@ class InvalidPaddingError(HyperframeError):
4240
.. versionchanged:: 6.0.0
4341
Changed base class from `ValueError` to :class:`HyperframeError`
4442
"""
45-
pass
4643

4744

4845
class InvalidFrameError(HyperframeError):
@@ -54,7 +51,6 @@ class InvalidFrameError(HyperframeError):
5451
.. versionchanged:: 6.0.0
5552
Changed base class from `ValueError` to :class:`HyperframeError`
5653
"""
57-
pass
5854

5955

6056
class InvalidDataError(HyperframeError):
@@ -63,4 +59,3 @@ class InvalidDataError(HyperframeError):
6359
6460
.. versionadded:: 6.0.0
6561
"""
66-
pass

src/hyperframe/flags.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
hyperframe/flags
3-
~~~~~~~~~~~~~~~~
4-
5-
Defines basic Flag and Flags data structures.
2+
Basic Flag and Flags data structures.
63
"""
7-
from collections.abc import MutableSet
8-
from typing import NamedTuple, Iterable, Set, Iterator
4+
from __future__ import annotations
5+
6+
from collections.abc import Iterable, Iterator, MutableSet
7+
from typing import NamedTuple
98

109

1110
class Flag(NamedTuple):
@@ -21,12 +20,13 @@ class Flags(MutableSet): # type: ignore
2120
Will behave like a regular set(), except that a ValueError will be thrown
2221
when .add()ing unexpected flags.
2322
"""
23+
2424
def __init__(self, defined_flags: Iterable[Flag]) -> None:
25-
self._valid_flags = set(flag.name for flag in defined_flags)
26-
self._flags: Set[str] = set()
25+
self._valid_flags = {flag.name for flag in defined_flags}
26+
self._flags: set[str] = set()
2727

2828
def __repr__(self) -> str:
29-
return repr(sorted(list(self._flags)))
29+
return repr(sorted(self._flags))
3030

3131
def __contains__(self, x: object) -> bool:
3232
return self._flags.__contains__(x)
@@ -42,9 +42,6 @@ def discard(self, value: str) -> None:
4242

4343
def add(self, value: str) -> None:
4444
if value not in self._valid_flags:
45-
raise ValueError(
46-
"Unexpected flag: {}. Valid flags are: {}".format(
47-
value, self._valid_flags
48-
)
49-
)
45+
msg = f"Unexpected flag: {value}. Valid flags are: {self._valid_flags}"
46+
raise ValueError(msg)
5047
return self._flags.add(value)

0 commit comments

Comments
 (0)