Skip to content

Commit

Permalink
fix: ruff,pyright errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Sep 7, 2024
1 parent be9275b commit 2fa14c1
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 64 deletions.
3 changes: 3 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fixable = [
"PIE808", # unnecessary-range-start
"RUF020", # never-union
"NPY201", # numpy2-deprecation
"PT",
]
ignore = [
"TD",
Expand Down Expand Up @@ -87,6 +88,8 @@ ignore = [
# pydocstyle # TODO
"D100", # undocumented-public-module
"D104", # undocumented-public-package
# async
"ASYNC109", # async-function-with-timeout
]

[lint.per-file-ignores]
Expand Down
2 changes: 2 additions & 0 deletions src/async_wrapper/convert/_async.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# FIXME: pyright v1.1.379 && pylance v2024.8.2
# pyright: reportUnnecessaryTypeIgnoreComment=false
from __future__ import annotations

from functools import cached_property, partial, wraps
Expand Down
2 changes: 2 additions & 0 deletions src/async_wrapper/convert/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# FIXME: pyright v1.1.379 && pylance v2024.8.2
# pyright: reportUnnecessaryTypeIgnoreComment=false
from __future__ import annotations

from inspect import iscoroutinefunction
Expand Down
2 changes: 1 addition & 1 deletion tests/convert/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def engine(
await engine.dispose()


@pytest.fixture()
@pytest.fixture
async def session(engine: AsyncEngine) -> AsyncGenerator[AsyncSession, None]:
async with AsyncSession(engine) as session:
yield session
Expand Down
5 changes: 3 additions & 2 deletions tests/convert/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import anyio
import pytest
from anyio.lowlevel import checkpoint
from sniffio import current_async_library
from typing_extensions import TypeVar

Expand Down Expand Up @@ -50,7 +51,7 @@ def test_toggle(self, x: int):
sample(x, self.epsilon)
assert self.epsilon * x < timer.term < self.epsilon * x + self.epsilon

@pytest.mark.anyio()
@pytest.mark.anyio
@pytest.mark.parametrize("x", range(1, 4))
async def test_async_to_sync_in_async(self, x: int):
backend = current_async_library()
Expand All @@ -72,7 +73,7 @@ def __await__(self) -> Generator[Any, None, ValueT]:

def sample_coroutine(value: ValueT) -> Coroutine[Any, Any, ValueT]:
async def inner() -> ValueT:
await anyio.sleep(0)
await checkpoint()
return value

return inner()
Expand Down
4 changes: 2 additions & 2 deletions tests/convert/test_toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from collections.abc import Callable
from typing import Any

import anyio
import pytest
from anyio.lowlevel import checkpoint

from async_wrapper import toggle_func

Expand All @@ -14,7 +14,7 @@ def sample_sync_func(x: Any) -> Any:


async def sample_async_func(x: Any) -> Any:
await anyio.sleep(0)
await checkpoint()
return x


Expand Down
2 changes: 1 addition & 1 deletion tests/task_group/test_task_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from async_wrapper.task_group import SoonValue


@pytest.mark.anyio()
@pytest.mark.anyio
class TestTaskGroupWrapper:
epsilon: Final[float] = 0.1

Expand Down
2 changes: 1 addition & 1 deletion tests/task_group/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_value_setattr(x: int):
assert maybe == x


@pytest.mark.anyio()
@pytest.mark.anyio
@pytest.mark.parametrize("x", range(4))
async def test_value_setattr_async(x: int):
value: SoonValue[Any] = SoonValue()
Expand Down
27 changes: 14 additions & 13 deletions tests/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import anyio
import pytest
from anyio.lowlevel import checkpoint
from typing_extensions import TypeVar, override

from .base import Timer
Expand Down Expand Up @@ -41,12 +42,12 @@ def is_disposed(self) -> bool:
return self.disposed

async def next(self, value: Any) -> Any:
await anyio.sleep(0)
await checkpoint()
self.value = value
return value

async def dispose(self) -> Any:
await anyio.sleep(0)
await checkpoint()
self.disposed = True

if self._dispose is not None:
Expand Down Expand Up @@ -121,25 +122,25 @@ def subscribable_type(request: pytest.FixtureRequest) -> type[Subscribable[Any,


async def as_tuple(value: ValueT) -> tuple[ValueT]:
await anyio.sleep(0)
await checkpoint()
return (value,)


async def return_self(value: ValueT) -> ValueT:
await anyio.sleep(0)
await checkpoint()
return value


def use_value():
result = None

async def getter() -> Any:
await anyio.sleep(0)
await checkpoint()
return result

async def setter(value: Any) -> None:
nonlocal result
await anyio.sleep(0)
await checkpoint()
result = value

return getter, setter
Expand All @@ -154,7 +155,7 @@ def check_hit() -> None:

async def hit(value: Any) -> None: # noqa: ARG001
nonlocal flag
await anyio.sleep(0)
await checkpoint()
flag = True

pipe = Pipe(hit)
Expand Down Expand Up @@ -213,7 +214,7 @@ async def test_subscribe_many(x: int, subscribable_type: type[Subscribable[Any,

async def hit(value: Any, index: int) -> None:
nonlocal check
await anyio.sleep(0)
await checkpoint()
check[index] = value

pipe: Subscribable[int, tuple[Any, ...]] = _construct_subcribable(
Expand Down Expand Up @@ -304,7 +305,7 @@ async def test_dispose(subscribable_type: type[Subscribable[Any, Any]]):

async def hit() -> None:
nonlocal flag
await anyio.sleep(0)
await checkpoint()
flag = True

pipe: Subscribable[Any, Any]
Expand All @@ -329,7 +330,7 @@ async def test_dispose_many(subscribable_type: type[Subscribable[Any, Any]]):

async def hit(index: int) -> None:
nonlocal check
await anyio.sleep(0)
await checkpoint()
check[index] = True

pipe: Subscribable[Any, Any] = _construct_subcribable(
Expand Down Expand Up @@ -369,7 +370,7 @@ async def test_pipe_dispose_only_once():

async def hit() -> None:
nonlocal count
await anyio.sleep(0)
await checkpoint()
count += 1

pipe = Pipe(return_self, dispose=hit)
Expand All @@ -384,7 +385,7 @@ async def test_do_not_dispose(subscribable_type: type[Subscribable[Any, Any]]):

async def hit() -> None:
nonlocal flag
await anyio.sleep(0)
await checkpoint()
flag = True

pipe: Subscribable[int, int] = _construct_subcribable(
Expand Down Expand Up @@ -467,7 +468,7 @@ async def test_pipe_next_after_disposed():

async def hit(value: Any) -> None: # noqa: ARG001
nonlocal flag
await anyio.sleep(0)
await checkpoint()
flag = True

pipe = Pipe(hit)
Expand Down
Loading

0 comments on commit 2fa14c1

Please sign in to comment.