Skip to content

Commit

Permalink
BREAKING_CHANGE: move execute_{sync,async} methods to SolvedDependent (
Browse files Browse the repository at this point in the history
…#91)

There are backwards compatibility shims on Container.execute_{sync,async} so this should, in theory, not break any code, but it is nontheless a pretty large API change.

This is (hopefully, time permitting) going to be a part of a larger effort to simplify the APIs and implementation of this library.
  • Loading branch information
adriangb authored Jan 23, 2023
1 parent c4da56c commit 52ea1c8
Show file tree
Hide file tree
Showing 44 changed files with 766 additions and 846 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
executor = SyncExecutor()
solved = container.solve(Dependent(C, scope="request"), scopes=["request"])
with container.enter_scope("request") as state:
c = container.execute_sync(solved, executor=executor, state=state)
c = solved.execute_sync(executor=executor, state=state)
assert isinstance(c, C)
assert isinstance(c.a, A)
assert isinstance(c.b, B)
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from pyinstrument.profiler import Profiler # type: ignore[import]

from benchmarks.utils import GraphSize, SleepTimes, generate_dag
from di import Container
from di.api.executor import SupportsAsyncExecutor, SupportsSyncExecutor
from di.container import Container
from di.dependent import Dependent
from di.executors import AsyncExecutor, ConcurrentAsyncExecutor, SyncExecutor

Expand All @@ -29,11 +29,11 @@ async def async_bench(
)
p = Profiler()
async with container.enter_scope(None) as state:
await container.execute_async(solved, executor=executor, state=state)
await solved.execute_async(executor=executor, state=state)
p.start()
for _ in range(iters):
async with container.enter_scope(None) as state:
await container.execute_async(solved, executor=executor, state=state)
await solved.execute_async(executor=executor, state=state)
p.stop()
p.print()
with open(f"bench_html/{name}.html", mode="w") as f:
Expand All @@ -54,11 +54,11 @@ def sync_bench(
executor = SyncExecutor()
p = Profiler()
with container.enter_scope(None) as state:
container.execute_sync(solved, executor=executor, state=state)
solved.execute_sync(executor=executor, state=state)
p.start()
for _ in range(iters):
with container.enter_scope(None) as state:
container.execute_sync(solved, executor=executor, state=state)
solved.execute_sync(executor=executor, state=state)
p.stop()
p.print()
with open(f"bench_html/{name}.html", mode="w") as f:
Expand Down
3 changes: 3 additions & 0 deletions di/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from di._container import Container, ScopeState, SolvedDependent, bind_by_type

__all__ = ("Container", "SolvedDependent", "bind_by_type", "ScopeState")
Loading

0 comments on commit 52ea1c8

Please sign in to comment.