Skip to content

Commit

Permalink
Bump to 1.3.0
Browse files Browse the repository at this point in the history
* Fix missing `factory` argument in `subtype()`
* Fix `asyncio.get_event_loop()` deprecation warning
  • Loading branch information
treykeown committed May 10, 2024
1 parent 075b2a4 commit 8664879
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion arguably/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "etc/pypi/PYPI_README.md"
Expand Down
7 changes: 6 additions & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8664879

Please sign in to comment.