Skip to content

Commit fa0e88c

Browse files
chore: review comment and test
1 parent 1b5498b commit fa0e88c

2 files changed

Lines changed: 377 additions & 5 deletions

File tree

cmd2/annotated.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ def _const_mismatches_type(a: _ArgparseArgument) -> bool:
19581958
(
19591959
# A block field's default must live on the dataclass field: a field default emits SUPPRESS (see
19601960
# _DEFAULT_RULES) so the dataclass constructor produces the value fresh on every call.
1961-
lambda a: a.is_block_field and not a.has_default and a.default is not _UNSET and a.default is not None,
1961+
lambda a: a.is_block_field and not a.has_default and a.default is not _UNSET,
19621962
lambda a: TypeError(
19631963
f"ArgumentBlock field '{a.name}' in {a.func_qualname} would take its default ({a.default!r}) from "
19641964
f"the option metadata or its action, but a block field's default must live on the dataclass field "
@@ -2113,7 +2113,7 @@ def _resolve_func_hints(func: Callable[..., Any], *, skip_params: frozenset[str]
21132113
) from exc
21142114

21152115

2116-
def _is_argument_block(hint: Any, param: inspect.Parameter) -> TypeGuard[type]:
2116+
def _is_argument_block(hint: Any, param: inspect.Parameter) -> TypeGuard[type[ArgumentBlock]]:
21172117
"""Whether a parameter is a bare [`ArgumentBlock`][cmd2.annotated.ArgumentBlock] whose fields expand flat.
21182118
21192119
Only a by-keyword-passable parameter (positional-or-keyword or keyword-only) annotated with a bare
@@ -2128,7 +2128,7 @@ def _is_argument_block(hint: Any, param: inspect.Parameter) -> TypeGuard[type]:
21282128
)
21292129

21302130

2131-
def _require_magic_block(name: str, hint: Any, param: inspect.Parameter, func_qualname: str) -> type:
2131+
def _require_magic_block(name: str, hint: Any, param: inspect.Parameter, func_qualname: str) -> type[ArgumentBlock]:
21322132
"""Return the ``ArgumentBlock`` subclass annotating a ``cmd2_base_args``/``cmd2_parent_args`` parameter.
21332133
21342134
Both magic parameters must be a bare ``ArgumentBlock`` subclass, the same form a regular block uses. A
@@ -2143,7 +2143,7 @@ def _require_magic_block(name: str, hint: Any, param: inspect.Parameter, func_qu
21432143
)
21442144

21452145

2146-
def _find_argument_block(hint: Any) -> type | None:
2146+
def _find_argument_block(hint: Any) -> type[ArgumentBlock] | None:
21472147
"""Return an [`ArgumentBlock`][cmd2.annotated.ArgumentBlock] subclass found anywhere within *hint*, else ``None``.
21482148
21492149
Used to reject a block that is not the bare annotation: an ``ArgumentBlock`` nested in ``Annotated`` /
@@ -2256,7 +2256,7 @@ def _expand_dataclass_block(
22562256
class _BlockSpec(NamedTuple):
22572257
"""How to reconstruct one dataclass-block parameter from the parsed namespace at call time."""
22582258

2259-
dc_type: type
2259+
dc_type: type[ArgumentBlock]
22602260
field_names: list[str]
22612261
inherited: bool # True for a cmd2_parent_args block (inherited from an ancestor's cmd2_base_args)
22622262
shared: bool = False # cmd2_base_args/cmd2_parent_args: fields live under a type-qualified dest

0 commit comments

Comments
 (0)