core: improve mypy type checks without generating runtime problems
This commit is contained in:
parent
9aebbff176
commit
48a5105eea
1 changed files with 18 additions and 6 deletions
|
|
@ -2,21 +2,33 @@
|
|||
|
||||
"""The scopes.core package"""
|
||||
|
||||
from __future__ import annotations # no check of type annotations at runtime
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
from types import CoroutineType, FunctionType
|
||||
from collections.abc import AsyncGenerator, Callable, Coroutine
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from scopes.core.message import Message
|
||||
from scopes.util import keywords as k, Symbol
|
||||
|
||||
type Proc = Callable[[Scope, Message], AsyncGenerator[Scope]]
|
||||
type Program = Callable[[Scope], Proc]
|
||||
type Syn = Callable[[Message], Message]
|
||||
|
||||
async def proc_dummy(scope: Scope, msg: Message) -> AsyncGenerator[Scope]:
|
||||
yield scope
|
||||
|
||||
@dataclass
|
||||
class Scope:
|
||||
|
||||
value: Any = 0
|
||||
categ: tuple[Symbol, Symbol] = (k.csys, k.c00)
|
||||
stage: Symbol = k.initial
|
||||
proc: CoroutineType | None = None
|
||||
program: dict[tuple[Symbol, Symbol], CoroutineType] = {}
|
||||
syns: list[FunctionType] = []
|
||||
environ: asyncio.Queue | None = None
|
||||
proc: Proc = proc_dummy
|
||||
program: Program = lambda x: proc_dummy
|
||||
syns: list[Syn] = field(default_factory=list)
|
||||
environ: asyncio.Queue = field(default_factory=asyncio.Queue)
|
||||
|
||||
def set_proc(self) -> Scope:
|
||||
self.proc = self.program(self)
|
||||
return self
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue