From 1d7d03c6ac46a46eaed97768e1626085c81a9094 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 15 Apr 2022 15:54:11 -0700 Subject: [PATCH] Rename AsyncRegistry to Registry --- README.md | 12 ++++++------ asyncinject/__init__.py | 2 +- tests/test_asyncinject.py | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0439acd..40ff95e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) ``` @@ -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" @@ -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, diff --git a/asyncinject/__init__.py b/asyncinject/__init__.py index d60a9a8..1f60ac6 100644 --- a/asyncinject/__init__.py +++ b/asyncinject/__init__.py @@ -7,7 +7,7 @@ import asyncio -class AsyncRegistry: +class Registry: def __init__(self, *fns, parallel=True, log=None): self._registry = {} self._graph = None diff --git a/tests/test_asyncinject.py b/tests/test_asyncinject.py index 003ec3c..bc443ef 100644 --- a/tests/test_asyncinject.py +++ b/tests/test_asyncinject.py @@ -1,6 +1,6 @@ import asyncio import pytest -from asyncinject import AsyncRegistry +from asyncinject import Registry from random import random @@ -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 @@ -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 @@ -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 @@ -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