Skip to content

Commit

Permalink
Fix ConstraintMixin.parse_args return value and add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
janluke committed Jun 30, 2021
1 parent 3f5dc2a commit 94f0d30
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cloup/constraints/_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,34 @@ def __init__(

# Collect constraints applied to option groups and bind them to the
# corresponding Option instances
option_groups: Sequence[OptionGroup] = getattr(self, 'option_groups', [])
option_groups: Tuple[OptionGroup, ...] = getattr(self, 'option_groups', [])
self._optgroup_constraints = tuple(
BoundConstraint(grp.constraint, grp.options)
for grp in option_groups
if grp.constraint is not None
)
# Bind constraints defined via @constraint to Parameter instances
self._extra_constraints: Sequence[BoundConstraint] = tuple(
self._extra_constraints: Tuple[BoundConstraint, ...] = tuple(
(
constr if isinstance(constr, BoundConstraint)
else constr.resolve_params(self)
)
for constr in constraints
)

def parse_args(self, ctx, args):
def parse_args(self, ctx: Context, args: List[str]) -> List[str]:
all_constraints = self._optgroup_constraints + self._extra_constraints
# Check parameter groups' consistency *before* parsing
if Constraint.must_check_consistency(ctx):
for constr in all_constraints:
constr.check_consistency()
super().parse_args(ctx, args)

args = super().parse_args(ctx, args) # type: ignore

# Validate constraints against parameter values
for constr in all_constraints:
constr.check_values(ctx)
return args

def get_param_by_name(self, name: str) -> Parameter:
try:
Expand Down

0 comments on commit 94f0d30

Please sign in to comment.