Skip to content

Commit

Permalink
Dependencies were updated. (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius authored Aug 29, 2024
1 parent d6786c1 commit 739be3c
Show file tree
Hide file tree
Showing 12 changed files with 709 additions and 820 deletions.
131 changes: 0 additions & 131 deletions .flake8

This file was deleted.

5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ repos:
pass_filenames: false
types: [python]
args:
- "check"
- "--fix"
- "taskiq"
- "tests"
Expand All @@ -37,4 +38,8 @@ repos:
name: Validate types with MyPy
entry: poetry run mypy
language: system
pass_filenames: false
types: [python]
args:
- ./taskiq
- ./tests
1,334 changes: 673 additions & 661 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ pyzmq = { version = "^23.2.0", optional = true, markers = "python_version < '3.1
# For speed
uvloop = { version = ">=0.16.0,<1", optional = true, markers = "sys_platform != 'win32'" }
# For hot-reload.
watchdog = { version = "^2.1.9", optional = true }
watchdog = { version = "^4", optional = true }
gitignore-parser = { version = "^0", optional = true }
pytz = "*"
orjson = { version = "^3.9.9", optional = true }
orjson = { version = "^3", optional = true }
msgpack = { version = "^1.0.7", optional = true }
cbor2 = { version = "^5.4.6", optional = true }
cbor2 = { version = "^5", optional = true }

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
ruff = "^0.0.291"
ruff = "^0"
black = { version = "^22.6.0", allow-prereleases = true }
mypy = "^1"
pre-commit = "^2.20.0"
Expand Down Expand Up @@ -120,7 +120,7 @@ build-backend = "poetry.core.masonry.api"
[tool.ruff]
# List of enabled rulsets.
# See https://docs.astral.sh/ruff/rules/ for more information.
select = [
lint.select = [
"E", # Error
"F", # Pyflakes
"W", # Pycodestyle
Expand All @@ -147,7 +147,7 @@ select = [
"PL", # PyLint checks
"RUF", # Specific to Ruff checks
]
ignore = [
lint.ignore = [
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
"D212", # Multi-line docstring summary should start at the first line
Expand All @@ -161,10 +161,10 @@ ignore = [
"D106", # Missing docstring in public nested class
]
exclude = [".venv/"]
mccabe = { max-complexity = 10 }
lint.mccabe = { max-complexity = 10 }
line-length = 88

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"S101", # Use of assert detected
"S301", # Use of pickle detected
Expand All @@ -174,12 +174,12 @@ line-length = 88
"D101", # Missing docstring in public class
]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "pep257"
ignore-decorators = ["typing.overload"]

[tool.ruff.pylint]
[tool.ruff.lint.pylint]
allow-magic-value-types = ["int", "str", "float"]

[tool.ruff.flake8-bugbear]
[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = ["taskiq_dependencies.Depends", "taskiq.TaskiqDepends"]
6 changes: 3 additions & 3 deletions taskiq/abc/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ def inner(
),
)

self._register_task(decorated_task.task_name, decorated_task)
self._register_task(decorated_task.task_name, decorated_task) # type: ignore

return decorated_task
return decorated_task # type: ignore

return inner

Expand Down Expand Up @@ -417,7 +417,7 @@ def add_event_handler(

def with_result_backend(
self,
result_backend: "AsyncResultBackend[_T]",
result_backend: "AsyncResultBackend[Any]",
) -> "Self": # pragma: no cover
"""
Set a result backend and return updated broker.
Expand Down
4 changes: 4 additions & 0 deletions taskiq/kicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def _prepare_arg(cls, arg: Any) -> Any:
if isinstance(arg, BaseModel):
arg = model_dump(arg)
if is_dataclass(arg):
if isinstance(arg, type):
raise ValueError(
f"Cannot serialize types. The {arg} is not serializable.",
)
arg = asdict(arg)
return arg

Expand Down
2 changes: 1 addition & 1 deletion taskiq/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def prepare_label(label_value: Any) -> Tuple[str, int]:
var_type = type(label_value)
if var_type in (int, str, float, bool):
return str(label_value), LabelType[var_type.__name__.upper()].value
if var_type == bytes:
if var_type is bytes:
return base64.b64encode(label_value).decode(), LabelType.BYTES.value
return str(label_value), LabelType.ANY.value

Expand Down
12 changes: 7 additions & 5 deletions taskiq/serializers/cbor_serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from typing import Any, Callable, Optional
from typing import Any, Callable, Dict, Optional

from taskiq.abc.serializer import TaskiqSerializer

Expand All @@ -26,8 +26,10 @@ def __init__(
date_as_datetime: bool = True,
string_referencing: bool = True,
# Decoder options
tag_hook: "Optional[Callable[[cbor2.CborDecoder, Any], Any]]" = None,
object_hook: Optional[Callable[[Any], Any]] = None,
tag_hook: Optional[Callable[["cbor2.CBORDecoder", Any], Any]] = None,
object_hook: Optional[
Callable[["cbor2.CBORDecoder", Dict[Any, Any]], Any]
] = None,
) -> None:
if cbor2 is None:
raise ImportError("cbor2 is not installed")
Expand All @@ -43,7 +45,7 @@ def __init__(

def dumpb(self, value: Any) -> bytes:
"""Dump value to bytes."""
return cbor2.dumps(
return cbor2.dumps( # type: ignore
value,
datetime_as_timestamp=self.datetime_as_timestamp,
timezone=self.timezone,
Expand All @@ -56,7 +58,7 @@ def dumpb(self, value: Any) -> bytes:

def loadb(self, value: bytes) -> Any:
"""Load value from bytes."""
return cbor2.loads(
return cbor2.loads( # type: ignore
value,
tag_hook=self.tag_hook,
object_hook=self.object_hook,
Expand Down
2 changes: 1 addition & 1 deletion taskiq/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import UserDict
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING: # pragma: no cover # noqa: SIM108
if TYPE_CHECKING: # pragma: no cover
_Base = UserDict[str, Any]
else:
_Base = UserDict
Expand Down
2 changes: 1 addition & 1 deletion tests/receiver/test_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_func() -> None:
assert result.return_value is None
assert result.is_err
assert len(_TestMiddleware.found_exceptions) == 1
assert _TestMiddleware.found_exceptions[0].__class__ == ValueError
assert _TestMiddleware.found_exceptions[0].__class__ is ValueError


@pytest.mark.anyio
Expand Down
2 changes: 0 additions & 2 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def test_exception_to_python_when_type_error() -> None:

def test_json_context() -> None:
error1 = ValueError("Context")
ValueError("Cause")
error3 = ValueError("Error")

try:
Expand Down Expand Up @@ -336,7 +335,6 @@ def test_json_cause() -> None:

def test_pickle_context() -> None:
error1 = ValueError("Context")
ValueError("Cause")
error3 = ValueError("Error")

try:
Expand Down
7 changes: 3 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import AsyncGenerator

from taskiq import AsyncBroker, BrokerMessage
from taskiq.acks import AckableMessage


class AsyncQueueBroker(AsyncBroker):
Expand All @@ -24,10 +25,8 @@ async def wait_tasks(self) -> None:
"""Small method to wait for all tasks to be processed."""
await self.queue.join()

async def listen(self) -> AsyncGenerator[bytes, None]:
async def listen(self) -> AsyncGenerator[AckableMessage, None]:
"""This method returns all tasks from queue."""
while True:
task = await self.queue.get()
yield task
# Notify that task is done.
self.queue.task_done()
yield AckableMessage(data=task, ack=self.queue.task_done)

0 comments on commit 739be3c

Please sign in to comment.