Skip to content

Commit

Permalink
fix: creart.it, 0.23.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 12, 2023
1 parent 29193d3 commit a1d6304
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"creart~=0.3.0",
]
name = "graia-broadcast"
version = "0.23.2"
version = "0.23.3"
description = "a highly customizable, elegantly designed event system based on asyncio"

[tool.pdm.build]
Expand Down
34 changes: 5 additions & 29 deletions src/graia/broadcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from contextlib import asynccontextmanager
from typing import Callable, Dict, Iterable, List, Optional, Set, Type, Union

from creart import it

from .builtin.defer import DeferDispatcher
from .builtin.depend import DependDispatcher
from .builtin.derive import DeriveDispatcher
Expand Down Expand Up @@ -56,11 +54,7 @@ class Broadcast:

_background_tasks: Set[asyncio.Task] = set()

def __init__(
self,
*,
loop: Optional[asyncio.AbstractEventLoop] = None,
):
def __init__(self):
self.default_namespace = Namespace(name="default", default=True)
self.namespaces = []
self.listeners = []
Expand All @@ -69,15 +63,6 @@ def __init__(
self.prelude_dispatchers = [self.decorator_interface, DependDispatcher(), DeriveDispatcher()]
self.finale_dispatchers = [DeferDispatcher()]

if loop is not None:
import warnings

warnings.warn(
"The loop argument is deprecated since BroadcastControl 0.21, and scheduled for removal in Python 0.22.",
DeprecationWarning,
stacklevel=2,
)

@self.prelude_dispatchers.append
class BroadcastBuiltinDispatcher(BaseDispatcher):
@staticmethod
Expand All @@ -89,18 +74,6 @@ async def catch(interface: DispatcherInterface):
elif interface.annotation is DispatcherInterface:
return interface

@property
def loop(self):
import warnings

warnings.warn(
"The loop attribute is deprecated since 0.21, and scheduled for removal in 0.22.",
DeprecationWarning,
stacklevel=2,
)

return it(asyncio.AbstractEventLoop)

def default_listener_generator(self, event_class) -> Iterable[Listener]:
return list(
filter(
Expand Down Expand Up @@ -305,7 +278,10 @@ async def param_compile(
dii.ctx.reset(dii_token)

def postEvent(self, event: Dispatchable, upper_event: Optional[Dispatchable] = None):
task = it(asyncio.AbstractEventLoop).create_task(
if not hasattr(self, "_loop"):
from creart import it
self._loop = it(asyncio.AbstractEventLoop)
task = self._loop.create_task(
self.layered_scheduler(
listener_generator=self.default_listener_generator(event.__class__),
event=event,
Expand Down
7 changes: 6 additions & 1 deletion src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ async def r(ster):
s = time.time()
# print(s)
# cProfile.run("loop.run_until_complete(asyncio.gather(*tasks))")
loop.run_until_complete(asyncio.gather(*tasks))


async def main():
await asyncio.gather(*tasks)

asyncio.run(main())

e = time.time()
n1 = e - s
Expand Down

0 comments on commit a1d6304

Please sign in to comment.