Guard against ambiguity when current flag takes an optional value. .. versionadded:: 1.0
(self, value: Any)
| 379 | self.flag.set_value(True, cast=False) |
| 380 | |
| 381 | def check_ambiguity(self, value: Any) -> bool: |
| 382 | """ |
| 383 | Guard against ambiguity when current flag takes an optional value. |
| 384 | |
| 385 | .. versionadded:: 1.0 |
| 386 | """ |
| 387 | # No flag is currently being examined, or one is but it doesn't take an |
| 388 | # optional value? Ambiguity isn't possible. |
| 389 | if not (self.flag and self.flag.optional): |
| 390 | return False |
| 391 | # We *are* dealing with an optional-value flag, but it's already |
| 392 | # received a value? There can't be ambiguity here either. |
| 393 | if self.flag.raw_value is not None: |
| 394 | return False |
| 395 | # Otherwise, there *may* be ambiguity if 1 or more of the below tests |
| 396 | # fail. |
| 397 | tests = [] |
| 398 | # Unfilled posargs still exist? |
| 399 | tests.append(self.context and self.context.missing_positional_args) |
| 400 | # Value matches another valid task/context name? |
| 401 | tests.append(value in self.contexts) |
| 402 | if any(tests): |
| 403 | msg = "{!r} is ambiguous when given after an optional-value flag" |
| 404 | raise ParseError(msg.format(value)) |
| 405 | |
| 406 | def switch_to_flag(self, flag: str, inverse: bool = False) -> None: |
| 407 | # Sanity check for ambiguity w/ prior optional-value flag |
no test coverage detected