Skip to content

Commit

Permalink
lint++
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriechi committed Dec 21, 2024
1 parent 2595cf6 commit 0be70d1
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 226 deletions.
Empty file added docs/source/_static/.keep
Empty file.
39 changes: 36 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://packaging.python.org/en/latest/specifications/pyproject-toml/

[build-system]
requires = ["setuptools"]
requires = ["setuptools>=75.6.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -92,8 +92,41 @@ ignore = [
]

[tool.ruff]
line-length = 140
line-length = 150
target-version = "py39"
format.preview = true
format.docstring-code-line-length = 100
format.docstring-code-format = true
lint.select = [
"ALL",
]
lint.ignore = [
"ANN401", # kwargs with typing.Any
"CPY", # not required
"D101", # docs readability
"D102", # docs readability
"D105", # docs readability
"D107", # docs readability
"D200", # docs readability
"D205", # docs readability
"D205", # docs readability
"D203", # docs readability
"D212", # docs readability
"D400", # docs readability
"D401", # docs readability
"D415", # docs readability
"PLR2004", # readability
"SIM108", # readability
"RUF012", # readability
"FBT001", # readability
"FBT002", # readability
"PGH003", # readability
]
lint.isort.required-imports = [ "from __future__ import annotations" ]

[tool.mypy]
show_error_codes = true
strict = true

[tool.coverage.run]
branch = true
Expand All @@ -104,7 +137,7 @@ fail_under = 100
show_missing = true
exclude_lines = [
"pragma: no cover",
"raise NotImplementedError()",
"raise NotImplementedError",
]

[tool.coverage.paths]
Expand Down
9 changes: 4 additions & 5 deletions src/hyperframe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
hyperframe
~~~~~~~~~~
A module for providing a pure-Python HTTP/2 framing layer.
Provides a pure-Python HTTP/2 framing layer.
"""
__version__ = '6.1.0+dev'
from __future__ import annotations

__version__ = "6.1.0+dev"
13 changes: 4 additions & 9 deletions src/hyperframe/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
hyperframe/exceptions
~~~~~~~~~~~~~~~~~~~~~
Defines the exceptions that can be thrown by hyperframe.
Exceptions that can be thrown by hyperframe.
"""
from __future__ import annotations


class HyperframeError(Exception):
Expand All @@ -21,6 +19,7 @@ class UnknownFrameError(HyperframeError):
.. versionchanged:: 6.0.0
Changed base class from `ValueError` to :class:`HyperframeError`
"""

def __init__(self, frame_type: int, length: int) -> None:
#: The type byte of the unknown frame that was received.
self.frame_type = frame_type
Expand All @@ -30,8 +29,7 @@ def __init__(self, frame_type: int, length: int) -> None:

def __str__(self) -> str:
return (
"UnknownFrameError: Unknown frame type 0x%X received, "
"length %d bytes" % (self.frame_type, self.length)
f"UnknownFrameError: Unknown frame type 0x{self.frame_type:X} received, length {self.length} bytes"
)


Expand All @@ -42,7 +40,6 @@ class InvalidPaddingError(HyperframeError):
.. versionchanged:: 6.0.0
Changed base class from `ValueError` to :class:`HyperframeError`
"""
pass


class InvalidFrameError(HyperframeError):
Expand All @@ -54,7 +51,6 @@ class InvalidFrameError(HyperframeError):
.. versionchanged:: 6.0.0
Changed base class from `ValueError` to :class:`HyperframeError`
"""
pass


class InvalidDataError(HyperframeError):
Expand All @@ -63,4 +59,3 @@ class InvalidDataError(HyperframeError):
.. versionadded:: 6.0.0
"""
pass
25 changes: 11 additions & 14 deletions src/hyperframe/flags.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
hyperframe/flags
~~~~~~~~~~~~~~~~
Defines basic Flag and Flags data structures.
Basic Flag and Flags data structures.
"""
from collections.abc import MutableSet
from typing import NamedTuple, Iterable, Set, Iterator
from __future__ import annotations

from collections.abc import Iterable, Iterator, MutableSet
from typing import NamedTuple


class Flag(NamedTuple):
Expand All @@ -21,12 +20,13 @@ class Flags(MutableSet): # type: ignore
Will behave like a regular set(), except that a ValueError will be thrown
when .add()ing unexpected flags.
"""

def __init__(self, defined_flags: Iterable[Flag]) -> None:
self._valid_flags = set(flag.name for flag in defined_flags)
self._flags: Set[str] = set()
self._valid_flags = {flag.name for flag in defined_flags}
self._flags: set[str] = set()

def __repr__(self) -> str:
return repr(sorted(list(self._flags)))
return repr(sorted(self._flags))

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

def add(self, value: str) -> None:
if value not in self._valid_flags:
raise ValueError(
"Unexpected flag: {}. Valid flags are: {}".format(
value, self._valid_flags
)
)
msg = f"Unexpected flag: {value}. Valid flags are: {self._valid_flags}"
raise ValueError(msg)
return self._flags.add(value)
Loading

0 comments on commit 0be70d1

Please sign in to comment.