Skip to content

Commit

Permalink
Add stubs with type hints for add_graph_output and const. This allows…
Browse files Browse the repository at this point in the history
… static type checking (and hence IDE autocomplete) to pick up the correct signatures

Signed-off-by: Pascal Tomecek <[email protected]>
  • Loading branch information
ptomecek committed Jul 16, 2024
1 parent 760097e commit 7063039
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions csp/baselib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import threading
import typing
from datetime import datetime, timedelta
from typing_extensions import override

import csp
from csp.impl.__cspimpl import _cspimpl
from csp.impl.constants import UNSET
from csp.impl.types.common_definitions import OutputBasket, Outputs
from csp.impl.types.common_definitions import OutputBasket, Outputs, PushMode
from csp.impl.types.tstype import ts
from csp.impl.wiring import DelayedEdge, Edge, OutputsContainer, graph, input_adapter_def, node
from csp.impl.wiring.delayed_node import DelayedNodeWrapperDef
Expand Down Expand Up @@ -69,7 +70,14 @@
Y = typing.TypeVar("Y")
U = typing.TypeVar("U")

const = input_adapter_def("csp.const", _cspimpl._const, ts["T"], value="~T", delay=(timedelta, timedelta()))

@override
def const(value: "~T", delay: timedelta = timedelta(), push_mode: PushMode = PushMode.NON_COLLAPSING) -> ts["T"]:
# Stub for IDE auto-complete/static type checking
...


const = input_adapter_def("csp.const", _cspimpl._const, ts["T"], value="~T", delay=(timedelta, timedelta())) # noqa: F811
_timer = input_adapter_def(
"csp.timer", _cspimpl._timer, ts["T"], interval=timedelta, value=("~T", True), allow_deviation=(bool, False)
)
Expand Down
14 changes: 13 additions & 1 deletion csp/impl/wiring/adapters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
from datetime import timedelta
from typing_extensions import override

from csp.impl.__cspimpl import _cspimpl
from csp.impl.mem_cache import csp_memoized_graph_object
Expand Down Expand Up @@ -363,7 +364,18 @@ def impl(mgr, engine, scalars):
)


add_graph_output = output_adapter_def(
@override
def add_graph_output(
key: object,
input: tstype.ts["T"], # noqa: F821
tick_count: int = -1,
tick_history: timedelta = timedelta(),
):
# Stub for IDE auto-complete/static type checking
...


add_graph_output = output_adapter_def( # noqa: F811
"add_graph_output",
_cspimpl._graph_output_adapter,
key=object,
Expand Down

0 comments on commit 7063039

Please sign in to comment.