Skip to content

Commit

Permalink
chore: update pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Jun 25, 2024
1 parent 3831390 commit 8b167b8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
6 changes: 0 additions & 6 deletions ckanext/files/cli/maintain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

from datetime import datetime, timezone

import click
import sqlalchemy as sa

Expand All @@ -11,10 +9,6 @@
from ckanext.files import shared, utils


def _now():
return datetime.now(timezone.utc)


@click.group()
def group():
"""Storage maintenance."""
Expand Down
2 changes: 1 addition & 1 deletion ckanext/files/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_str(self, faker: Faker):
"""Strings converted into Upload."""
string = faker.pystr()
with pytest.raises(TypeError):
utils.make_upload(string) # type: ignore
utils.make_upload(string)

def test_bytes(self, faker: Faker):
"""Bytes converted into Upload."""
Expand Down
15 changes: 14 additions & 1 deletion ckanext/files/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

from __future__ import annotations

from typing import Any, Iterator, Literal, Protocol
import tempfile
from io import TextIOWrapper
from typing import Any, BinaryIO, Iterator, Literal, Protocol, Union

from werkzeug.datastructures import FileStorage

from ckan.config.declaration import Declaration, Key
from ckan.types import (
Expand All @@ -18,6 +22,15 @@

AuthOperation = Literal["show", "update", "delete", "file_transfer"]

Uploadable = Union[
FileStorage,
tempfile.SpooledTemporaryFile[Any],
TextIOWrapper,
bytes,
bytearray,
BinaryIO,
]


class UploadStream(Protocol):
def read(self, size: Any = ..., /) -> bytes: ...
Expand Down
12 changes: 2 additions & 10 deletions ckanext/files/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import re
import tempfile
from io import BufferedReader, BytesIO, TextIOWrapper
from typing import Any, BinaryIO, Callable, Generic, Iterable, TypeVar, cast
from typing import Any, Callable, Generic, Iterable, TypeVar, cast

import jwt
import magic
Expand Down Expand Up @@ -306,15 +306,7 @@ def humanize_filesize(value: int | float) -> str:


def make_upload(
value: (
FileStorage
| Upload
| tempfile.SpooledTemporaryFile[Any]
| TextIOWrapper
| bytes
| bytearray
| BinaryIO
),
value: types.Uploadable | Upload,
) -> Upload:
"""Convert value into Upload object
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b167b8

Please sign in to comment.