Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgramRipper committed Jul 29, 2023
1 parent 76b0342 commit 47f54ba
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ exclude_lines = [
"def __repr_args__",
"except ImportError:", # Don't complain about import fallback
]

[tool.pyright]
pythonVersion = "3.7"
2 changes: 1 addition & 1 deletion src/graia/broadcast/builtin/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from ..entities.signatures import Force
from ..exceptions import RequirementCrashed
from ..interfaces.decorator import DecoratorInterface

from .depend import Depend as Depend


class OptionalParam(Decorator):
pre = True

Expand Down
3 changes: 2 additions & 1 deletion src/graia/broadcast/builtin/defer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

import asyncio
from types import TracebackType
from typing import Awaitable, Callable
Expand All @@ -9,7 +10,7 @@

class DeferDispatcher(BaseDispatcher):
async def beforeExecution(self, interface: DispatcherInterface):
interface.local_storage['defer_callbacks'] = []
interface.local_storage["defer_callbacks"] = []

async def catch(self, interface: DispatcherInterface):
return
Expand Down
27 changes: 12 additions & 15 deletions src/graia/broadcast/builtin/depend.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

from __future__ import annotations

from contextlib import (
AsyncExitStack,
asynccontextmanager,
contextmanager,
)
from contextlib import AsyncExitStack, asynccontextmanager, contextmanager
from inspect import isasyncgenfunction, isgeneratorfunction
from types import TracebackType
from typing import AsyncContextManager, Callable, ContextManager

from graia.broadcast.interfaces.dispatcher import DispatcherInterface as DispatcherInterface
from graia.broadcast.interfaces.dispatcher import (
DispatcherInterface as DispatcherInterface,
)

from ..entities.decorator import Decorator
from ..entities.dispatcher import BaseDispatcher
Expand Down Expand Up @@ -40,17 +37,17 @@ def __init__(self, callable: Callable, *, cache=False):
self.exec_target = ExecTarget(callable)

async def target(self, interface: DecoratorInterface):
cache: dict = interface.local_storage['_depend_cached_results']
cache: dict = interface.local_storage["_depend_cached_results"]
if self.raw in cache:
return cache[self.raw]

result_tier1 = await interface.dispatcher_interface.broadcast.Executor(
target=self.exec_target,
dispatchers=interface.dispatcher_interface.dispatchers,
depth=interface.dispatcher_interface.depth + 1,
)
stack: AsyncExitStack = interface.local_storage['_depend_lifespan_manager']
stack: AsyncExitStack = interface.local_storage["_depend_lifespan_manager"]

if isinstance(result_tier1, ContextManager):
result = stack.enter_context(result_tier1)
cache[self.raw] = result
Expand All @@ -61,14 +58,14 @@ async def target(self, interface: DecoratorInterface):
result = result_tier1
if self.cache:
cache[self.raw] = result

return Force(result)


class DependDispatcher(BaseDispatcher):
async def beforeExecution(self, interface: DispatcherInterface):
interface.local_storage['_depend_lifespan_manager'] = AsyncExitStack()
interface.local_storage['_depend_cached_results'] = {}
interface.local_storage["_depend_lifespan_manager"] = AsyncExitStack()
interface.local_storage["_depend_cached_results"] = {}

async def catch(self, interface: DispatcherInterface):
return
Expand All @@ -79,5 +76,5 @@ async def afterExecution(
exception: Exception | None,
tb: TracebackType | None,
):
stack: AsyncExitStack = interface.local_storage['_depend_lifespan_manager']
stack: AsyncExitStack = interface.local_storage["_depend_lifespan_manager"]
await stack.__aexit__(type(exception) if exception is not None else None, exception, tb)
1 change: 1 addition & 0 deletions src/test/deco.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

import pytest

from graia.broadcast import Broadcast
from graia.broadcast.builtin.decorators import Depend, OptionalParam
from graia.broadcast.entities.decorator import Decorator
Expand Down
1 change: 1 addition & 0 deletions src/test/dispatch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

import pytest

from graia.broadcast import Broadcast
from graia.broadcast.entities.dispatcher import BaseDispatcher
from graia.broadcast.entities.event import Dispatchable
Expand Down
1 change: 1 addition & 0 deletions src/test/get_throw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

import pytest

from graia.broadcast import Broadcast
from graia.broadcast.builtin.event import EventExceptionThrown
from graia.broadcast.entities.dispatcher import BaseDispatcher
Expand Down
1 change: 1 addition & 0 deletions src/test/postpone_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio

import pytest

from graia.broadcast import Broadcast
from graia.broadcast.entities.dispatcher import BaseDispatcher
from graia.broadcast.entities.event import Dispatchable
Expand Down

0 comments on commit 47f54ba

Please sign in to comment.