Skip to content

Commit 8664879

Browse files
committed
Bump to 1.3.0
* Fix missing `factory` argument in `subtype()` * Fix `asyncio.get_event_loop()` deprecation warning
1 parent 075b2a4 commit 8664879

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

arguably/_context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ def subtype(
938938
*,
939939
# Arguments below are passed through to `SubtypeDecoratorInfo`
940940
alias: str,
941+
factory: Callable | None = None,
941942
) -> Union[Callable[[type], type], type]:
942943
"""
943944
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(
947948
cls: The target class.
948949
alias: An alias for this class. For example, `@arguably.subtype(alias="foo")` would cause this class to be built
949950
any time an applicable arg is given a string starting with `foo,...`
951+
factory: What should be called to actually build the subtype. This should only be needed if the default behavior
952+
doesn't work.
950953
951954
Returns:
952955
If called with parens `@arguably.subtype(...)`, returns the decorated class. If called without parens
@@ -990,7 +993,7 @@ def wrap(cls_: type) -> type:
990993
raise ArguablyException(
991994
f"Decorated value {cls_} is not a type, which is required for `@arguably.subtype()`"
992995
)
993-
context.add_subtype(type_=cls_, alias=alias)
996+
context.add_subtype(type_=cls_, alias=alias, factory=factory)
994997
return cls_
995998

996999
# Handle being called as either @arguably.subtype or @arguably.subtype()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "arguably"
3-
version = "1.2.5"
3+
version = "1.3.0"
44
description = "The best Python CLI library, arguably."
55
authors = ["treykeown <[email protected]>"]
66
readme = "etc/pypi/PYPI_README.md"

test/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ def run_cli_and_manual(
3434
arguably_kwargs = dict()
3535

3636
if is_async:
37-
asyncio.get_event_loop().run_until_complete(func(*args, **kwargs))
37+
try:
38+
loop = asyncio.get_running_loop()
39+
except RuntimeError:
40+
loop = asyncio.new_event_loop()
41+
asyncio.set_event_loop(loop)
42+
loop.run_until_complete(func(*args, **kwargs))
3843
else:
3944
func(*args, **kwargs)
4045
manual = get_and_clear_io(iobuf)

0 commit comments

Comments
 (0)