From 86648796c4a28fa59f6f059b673694929c7df534 Mon Sep 17 00:00:00 2001 From: treykeown <2755914+treykeown@users.noreply.github.com> Date: Thu, 9 May 2024 20:58:01 -0400 Subject: [PATCH] Bump to 1.3.0 * Fix missing `factory` argument in `subtype()` * Fix `asyncio.get_event_loop()` deprecation warning --- arguably/_context.py | 5 ++++- pyproject.toml | 2 +- test/__init__.py | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arguably/_context.py b/arguably/_context.py index 156900f..9631fc6 100644 --- a/arguably/_context.py +++ b/arguably/_context.py @@ -938,6 +938,7 @@ def subtype( *, # Arguments below are passed through to `SubtypeDecoratorInfo` alias: str, + factory: Callable | None = None, ) -> Union[Callable[[type], type], type]: """ Mark a decorated class as a subtype that should be buildable for a parameter using arg.builder(). The alias @@ -947,6 +948,8 @@ def subtype( cls: The target class. alias: An alias for this class. For example, `@arguably.subtype(alias="foo")` would cause this class to be built any time an applicable arg is given a string starting with `foo,...` + factory: What should be called to actually build the subtype. This should only be needed if the default behavior + doesn't work. Returns: If called with parens `@arguably.subtype(...)`, returns the decorated class. If called without parens @@ -990,7 +993,7 @@ def wrap(cls_: type) -> type: raise ArguablyException( f"Decorated value {cls_} is not a type, which is required for `@arguably.subtype()`" ) - context.add_subtype(type_=cls_, alias=alias) + context.add_subtype(type_=cls_, alias=alias, factory=factory) return cls_ # Handle being called as either @arguably.subtype or @arguably.subtype() diff --git a/pyproject.toml b/pyproject.toml index e73400d..deb0e69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "arguably" -version = "1.2.5" +version = "1.3.0" description = "The best Python CLI library, arguably." authors = ["treykeown <2755914+treykeown@users.noreply.github.com>"] readme = "etc/pypi/PYPI_README.md" diff --git a/test/__init__.py b/test/__init__.py index 9040dd3..953447d 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -34,7 +34,12 @@ def run_cli_and_manual( arguably_kwargs = dict() if is_async: - asyncio.get_event_loop().run_until_complete(func(*args, **kwargs)) + try: + loop = asyncio.get_running_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + loop.run_until_complete(func(*args, **kwargs)) else: func(*args, **kwargs) manual = get_and_clear_io(iobuf)