File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -938,6 +938,7 @@ def subtype(
938
938
* ,
939
939
# Arguments below are passed through to `SubtypeDecoratorInfo`
940
940
alias : str ,
941
+ factory : Callable | None = None ,
941
942
) -> Union [Callable [[type ], type ], type ]:
942
943
"""
943
944
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(
947
948
cls: The target class.
948
949
alias: An alias for this class. For example, `@arguably.subtype(alias="foo")` would cause this class to be built
949
950
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.
950
953
951
954
Returns:
952
955
If called with parens `@arguably.subtype(...)`, returns the decorated class. If called without parens
@@ -990,7 +993,7 @@ def wrap(cls_: type) -> type:
990
993
raise ArguablyException (
991
994
f"Decorated value { cls_ } is not a type, which is required for `@arguably.subtype()`"
992
995
)
993
- context .add_subtype (type_ = cls_ , alias = alias )
996
+ context .add_subtype (type_ = cls_ , alias = alias , factory = factory )
994
997
return cls_
995
998
996
999
# Handle being called as either @arguably.subtype or @arguably.subtype()
Original file line number Diff line number Diff line change 1
1
[tool .poetry ]
2
2
name = " arguably"
3
- version = " 1.2.5 "
3
+ version = " 1.3.0 "
4
4
description = " The best Python CLI library, arguably."
5
5
authors = [
" treykeown <[email protected] >" ]
6
6
readme = " etc/pypi/PYPI_README.md"
Original file line number Diff line number Diff line change @@ -34,7 +34,12 @@ def run_cli_and_manual(
34
34
arguably_kwargs = dict ()
35
35
36
36
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 ))
38
43
else :
39
44
func (* args , ** kwargs )
40
45
manual = get_and_clear_io (iobuf )
You can’t perform that action at this time.
0 commit comments