Skip to content

Commit

Permalink
Rename AsyncRegistry to Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 15, 2022
1 parent eb6d896 commit 1d7d03c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The library can then create and execute a plan for executing the required functi
Here's an example, using the [httpx](https://www.python-httpx.org/) HTTP library.

```python
from asyncinject import AsyncRegistry
from asyncinject import Registry
import httpx


Expand All @@ -40,7 +40,7 @@ async def simonwillison():
async def both(example, simonwillison):
return example + "\n\n" + simonwillison

registry = AsyncRegistry(example, simonwillison, both)
registry = Registry(example, simonwillison, both)
combined = await registry.resolve(both)
print(combined)
```
Expand All @@ -65,7 +65,7 @@ async def both(get_param_1, get_param_2):
return get_param_1 + "\n\n" + get_param_2


combined = await AsyncRegistry(get_param_1, get_param_2, both).resolve(
combined = await Registry(get_param_1, get_param_2, both).resolve(
both,
param1 = "http://www.example.com/",
param2 = "https://simonwillison.net/search/?tag=empty"
Expand All @@ -83,15 +83,15 @@ async def go(calc1, x=5):
async def calc1():
return 5

print(await AsyncRegistry(calc1, go).resolve(go))
print(await Registry(calc1, go).resolve(go))
# Prints 10
```

### Debug logging

You can pass a `log=` callable to the `AsyncRegistry` constructor. Your function should take a single `message` argument - the easiest way to do this is to use `print`:
You can pass a `log=` callable to the `Registry` constructor. Your function should take a single `message` argument - the easiest way to do this is to use `print`:
```python
combined = await AsyncRegistry(
combined = await Registry(
get_param_1, get_param_2, both, log=print
).resolve(
both,
Expand Down
2 changes: 1 addition & 1 deletion asyncinject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import asyncio


class AsyncRegistry:
class Registry:
def __init__(self, *fns, parallel=True, log=None):
self._registry = {}
self._graph = None
Expand Down
10 changes: 5 additions & 5 deletions tests/test_asyncinject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import pytest
from asyncinject import AsyncRegistry
from asyncinject import Registry
from random import random


Expand All @@ -27,7 +27,7 @@ async def go(log, a):
log.append("go")
return log

return AsyncRegistry(log, d, c, b, a, go)
return Registry(log, d, c, b, a, go)


@pytest.mark.asyncio
Expand All @@ -52,7 +52,7 @@ async def calc1():
async def calc2():
return 6

registry = AsyncRegistry(go, calc1, calc2)
registry = Registry(go, calc1, calc2)
result = await registry.resolve(go, param1=4)
assert result == 15

Expand All @@ -73,7 +73,7 @@ async def calc1():
async def calc2(param1):
return 6 + param1

registry = AsyncRegistry(go, calc1, calc2)
registry = Registry(go, calc1, calc2)
result = await registry.resolve(go, param1=1)
assert result == 12

Expand All @@ -86,7 +86,7 @@ async def go(calc1, x=5):
async def calc1():
return 5

registry = AsyncRegistry(go, calc1)
registry = Registry(go, calc1)
result = await registry.resolve(go)
assert result == 10

Expand Down

0 comments on commit 1d7d03c

Please sign in to comment.