better __all__
This commit is contained in:
parent
06db9220f9
commit
18001ff340
@ -1,6 +1,9 @@
|
||||
from typing import Callable, Generic, TypeVar
|
||||
|
||||
from .context import Implicit
|
||||
from .context import *
|
||||
|
||||
__all__ = ('AtOf',)
|
||||
|
||||
|
||||
K = TypeVar('K')
|
||||
V = TypeVar('V')
|
||||
|
@ -1,10 +1,10 @@
|
||||
import asyncio
|
||||
import time
|
||||
from io import StringIO
|
||||
from typing import Awaitable, Callable, Optional, Union
|
||||
|
||||
import discord
|
||||
|
||||
__all__ = ('usertype', 'Context', 'escape', 'command_type', 'Explicit', 'Implicit')
|
||||
|
||||
usertype = Union[discord.abc.User, discord.user.BaseUser, discord.Member, discord.User]
|
||||
|
||||
|
||||
@ -57,30 +57,3 @@ class Explicit(Exception):
|
||||
|
||||
class Implicit(Exception):
|
||||
pass
|
||||
|
||||
|
||||
benchmarks: dict[str, dict[str, float]] = {}
|
||||
_t = time.perf_counter()
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, benchmark: str):
|
||||
self.benchmark = benchmark
|
||||
|
||||
def __enter__(self):
|
||||
self.t = time.perf_counter()
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
d = (time.perf_counter() - self.t)
|
||||
benchmarks.setdefault(self.benchmark, {'integral': 0.0, 'max': 0.0})
|
||||
benchmarks[self.benchmark]['integral'] += d
|
||||
benchmarks[self.benchmark]['max'] = max(benchmarks[self.benchmark]['max'], d)
|
||||
|
||||
|
||||
async def monitor():
|
||||
while True:
|
||||
await asyncio.sleep(10)
|
||||
dt = time.perf_counter() - _t
|
||||
print('Benchmarks:')
|
||||
for benchmark, metrics in benchmarks.items():
|
||||
print(benchmark, '=', metrics['integral'] / max(dt, .00001), ':', metrics['max'])
|
||||
|
@ -2,8 +2,10 @@ from typing import Callable
|
||||
|
||||
import discord
|
||||
|
||||
from v6d2ctx.context import Context, Explicit, Implicit, command_type
|
||||
from v6d2ctx.handle_command import handle_command
|
||||
from v6d2ctx.context import *
|
||||
from v6d2ctx.handle_command import *
|
||||
|
||||
__all__ = ('handle_args',)
|
||||
|
||||
|
||||
async def handle_args(of: Callable[[str], command_type], message: discord.Message, args: list[str], client: discord.Client):
|
||||
|
@ -1,6 +1,8 @@
|
||||
from typing import Awaitable, Callable
|
||||
from typing import Callable
|
||||
|
||||
from v6d2ctx.context import Context, command_type
|
||||
from v6d2ctx.context import *
|
||||
|
||||
__all__ = ('handle_command',)
|
||||
|
||||
|
||||
async def handle_command(of: Callable[[str], command_type], ctx: Context, name: str, args: list[str]) -> None:
|
||||
|
@ -3,9 +3,10 @@ from typing import Callable
|
||||
|
||||
import discord
|
||||
|
||||
from v6d2ctx.handle_args import handle_args
|
||||
from v6d2ctx.context import *
|
||||
from v6d2ctx.handle_args import *
|
||||
|
||||
from v6d2ctx.context import command_type
|
||||
__all__ = ('handle_content',)
|
||||
|
||||
|
||||
async def handle_content(of: Callable[[str], command_type], message: discord.Message, content: str, prefix: str, client: discord.Client):
|
||||
|
@ -1,15 +1,23 @@
|
||||
import asyncio
|
||||
from typing import Hashable
|
||||
|
||||
from v6d2ctx.context import Explicit
|
||||
from v6d2ctx.context import *
|
||||
|
||||
locks: dict[Hashable, asyncio.Lock] = {}
|
||||
__all__ = ('lock_for', 'Locks',)
|
||||
|
||||
|
||||
def lock_for(key: Hashable, error_message: str) -> asyncio.Lock:
|
||||
if key is None:
|
||||
raise Explicit(error_message)
|
||||
if key in locks:
|
||||
return locks[key]
|
||||
else:
|
||||
return locks.setdefault(key, asyncio.Lock())
|
||||
class Locks:
|
||||
def __init__(self) -> None:
|
||||
self.locks: dict[Hashable, asyncio.Lock] = {}
|
||||
|
||||
def lock_for(self, key: Hashable, error_message: str) -> asyncio.Lock:
|
||||
if key is None:
|
||||
raise Explicit(error_message)
|
||||
if key in self.locks:
|
||||
return self.locks[key]
|
||||
else:
|
||||
return self.locks.setdefault(key, asyncio.Lock())
|
||||
|
||||
|
||||
locks = Locks()
|
||||
lock_for = locks.lock_for
|
||||
|
@ -5,6 +5,8 @@ import time
|
||||
|
||||
from rainbowadn.instrument import Instrumentation
|
||||
|
||||
__all__ = ('ALog', 'SLog', 'FrameTrace', 'ABlockMonitor')
|
||||
|
||||
|
||||
class ALog(Instrumentation):
|
||||
start = time.time()
|
||||
@ -52,7 +54,7 @@ class FrameTrace(Instrumentation):
|
||||
|
||||
|
||||
class ABlockMonitor:
|
||||
__task: asyncio.Future
|
||||
__task: asyncio.Future[None]
|
||||
|
||||
def __init__(self, *, threshold=0.0, delta=10.0, interval=0.0) -> None:
|
||||
self.threshold = threshold
|
||||
|
@ -3,6 +3,8 @@ import signal
|
||||
|
||||
import discord
|
||||
|
||||
__all__ = ('serve',)
|
||||
|
||||
|
||||
def serve(main, client: discord.Client, loop: asyncio.AbstractEventLoop):
|
||||
async def aclose():
|
||||
|
Loading…
Reference in New Issue
Block a user