Skip to content

Commit 66793ec

Browse files
committed
Make it more modern
1 parent 2af2b4f commit 66793ec

File tree

7 files changed

+89
-6
lines changed

7 files changed

+89
-6
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: uv sync --python ${{ matrix.python-version }} --frozen
2929

3030
- name: Run linters
31-
run: scripts/lint
31+
run: scripts/check
3232

3333
- name: Run tests
3434
run: scripts/test

multipart/multipart.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class MultipartState(IntEnum):
162162
b"!#$%&'*+-.^_`|~")
163163
# fmt: on
164164

165+
165166
def parse_options_header(value: str | bytes | None) -> tuple[bytes, dict[bytes, bytes]]:
166167
"""Parses a Content-Type header into a value in the following format: (content_type, {parameters})."""
167168
# Uses email.message.Message to parse the header as described in PEP 594.
@@ -508,7 +509,7 @@ def _get_disk_file(self) -> BufferedRandom:
508509
if isinstance(tmp_file.name, str):
509510
fname = tmp_file.name.encode(sys.getfilesystemencoding())
510511
else:
511-
fname = cast(bytes, tmp_file.name)
512+
fname = cast(bytes, tmp_file.name) # pragma: no cover
512513

513514
self._actual_file_name = fname
514515
return tmp_file
@@ -597,7 +598,7 @@ def __init__(self) -> None:
597598
self.callbacks: QuerystringCallbacks | OctetStreamCallbacks | MultipartCallbacks = {}
598599

599600
def callback(
600-
self, name: CALLBACK_NAMES, data: bytes | None = None, start: int | None = None, end: int | None = None
601+
self, name: CallbackName, data: bytes | None = None, start: int | None = None, end: int | None = None
601602
) -> None:
602603
"""This function calls a provided callback with some data. If the
603604
callback is not set, will do nothing.
@@ -626,7 +627,7 @@ def callback(
626627
self.logger.debug("Calling %s with no data", on_name)
627628
func()
628629

629-
def set_callback(self, name: CALLBACK_NAMES, new_func: Callable[..., Any] | None) -> None:
630+
def set_callback(self, name: CallbackName, new_func: Callable[..., Any] | None) -> None:
630631
"""Update the function for a callback. Removes from the callbacks dict
631632
if new_func is None.
632633

scripts/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Development Scripts
2+
3+
* `scripts/setup` - Install dependencies.
4+
* `scripts/test` - Run the test suite.
5+
* `scripts/lint` - Run the code format.
6+
* `scripts/check` - Run the lint in check mode, and the type checker.
7+
8+
Styled after GitHub's ["Scripts to Rule Them All"](https://github.com/github/scripts-to-rule-them-all).

scripts/check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh -e
2+
3+
set -x
4+
5+
SOURCE_FILES="multipart tests"
6+
7+
uvx ruff format --check --diff $SOURCE_FILES
8+
uvx ruff check $SOURCE_FILES
9+
uvx --from types-PyYAML mypy $SOURCE_FILES

scripts/setup

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -ex
2+
3+
uv sync --frozen

tests/test_multipart.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ def test_not_aligned(self) -> None:
713713
"single_field_single_file",
714714
]
715715

716+
716717
def split_all(val: bytes) -> Iterator[tuple[bytes, bytes]]:
717718
"""
718719
This function will split an array all possible ways. For example:
@@ -863,7 +864,7 @@ def test_random_splitting(self) -> None:
863864
self.assert_field(b"field", b"test1")
864865
self.assert_file(b"file", b"file.txt", b"test2")
865866

866-
@parametrize("param", [ t for t in http_tests if t["name"] in single_byte_tests])
867+
@parametrize("param", [t for t in http_tests if t["name"] in single_byte_tests])
867868
def test_feed_single_bytes(self, param: TestParams) -> None:
868869
"""
869870
This test parses multipart bodies 1 byte at a time.

uv.lock

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)