Skip to content

typing++ and lint++ #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ dev
- Support for Python 3.6 has been removed.
- Support for Python 3.7 has been removed.
- Support for Python 3.8 has been removed.
- Renamed `InvalidTableIndex` exception to `InvalidTableIndexError`.

**API Changes (Backward Compatible)**

2 changes: 2 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ This document provides the HPACK API.

.. autoclass:: hpack.HPACKDecodingError

.. autoclass:: hpack.InvalidTableIndexError

.. autoclass:: hpack.InvalidTableIndex

.. autoclass:: hpack.OversizedHeaderListError
38 changes: 37 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ testing = [
linting = [
"ruff>=0.8.0,<1",
"mypy>=1.13.0,<2",
"typing_extensions>=4.12.2",
]

packaging = [
@@ -86,8 +87,43 @@ hpack = [ "py.typed" ]
version = { attr = "hpack.__version__" }

[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
"PGH004", # readability
"PYI034", # PEP 673 not yet available in Python 3.9 - only in 3.11+
]
lint.isort.required-imports = [ "from __future__ import annotations" ]

[tool.mypy]
show_error_codes = true
strict = true

[tool.pytest.ini_options]
testpaths = [ "tests" ]
36 changes: 15 additions & 21 deletions src/hpack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
"""
hpack
~~~~~

HTTP/2 header encoding for Python.
"""
from .hpack import Encoder, Decoder
from __future__ import annotations

from .exceptions import HPACKDecodingError, HPACKError, InvalidTableIndex, InvalidTableIndexError, InvalidTableSizeError, OversizedHeaderListError
from .hpack import Decoder, Encoder
from .struct import HeaderTuple, NeverIndexedHeaderTuple
from .exceptions import (
HPACKError,
HPACKDecodingError,
InvalidTableIndex,
OversizedHeaderListError,
InvalidTableSizeError
)

__all__ = [
'Encoder',
'Decoder',
'HeaderTuple',
'NeverIndexedHeaderTuple',
'HPACKError',
'HPACKDecodingError',
'InvalidTableIndex',
'OversizedHeaderListError',
'InvalidTableSizeError',
"Decoder",
"Encoder",
"HPACKDecodingError",
"HPACKError",
"HeaderTuple",
"InvalidTableIndex",
"InvalidTableIndexError",
"InvalidTableSizeError",
"NeverIndexedHeaderTuple",
"OversizedHeaderListError",
]

__version__ = '4.1.0+dev'
__version__ = "4.1.0+dev"
25 changes: 15 additions & 10 deletions src/hpack/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
"""
hyper/http20/exceptions
~~~~~~~~~~~~~~~~~~~~~~~

This defines exceptions used in the HTTP/2 portion of hyper.
Exceptions used in hpack.
"""
from __future__ import annotations


class HPACKError(Exception):
"""
The base class for all ``hpack`` exceptions.
"""
pass



class HPACKDecodingError(HPACKError):
"""
An error has been encountered while performing HPACK decoding.
"""
pass


class InvalidTableIndex(HPACKDecodingError):

class InvalidTableIndexError(HPACKDecodingError):
"""
An invalid table index was received.

.. versionadded:: 4.1.0
"""

class InvalidTableIndex(InvalidTableIndexError): # noqa: N818
"""
An invalid table index was received.

.. deprecated:: 4.1.0
Renamed to :class:`InvalidTableIndexError`, use it instead.
"""
pass


class OversizedHeaderListError(HPACKDecodingError):
@@ -34,7 +41,6 @@ class OversizedHeaderListError(HPACKDecodingError):

.. versionadded:: 2.3.0
"""
pass


class InvalidTableSizeError(HPACKDecodingError):
@@ -45,4 +51,3 @@ class InvalidTableSizeError(HPACKDecodingError):

.. versionadded:: 3.0.0
"""
pass
Loading