(self, flag: str, inverse: bool = False)
| 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 |
| 408 | self.check_ambiguity(flag) |
| 409 | # Also tie it off, in case prior had optional value or etc. Seems to be |
| 410 | # harmless for other kinds of flags. (TODO: this is a serious indicator |
| 411 | # that we need to move some of this flag-by-flag bookkeeping into the |
| 412 | # state machine bits, if possible - as-is it was REAL confusing re: why |
| 413 | # this was manually required!) |
| 414 | self.complete_flag() |
| 415 | # Set flag/arg obj |
| 416 | flag = self.context.inverse_flags[flag] if inverse else flag |
| 417 | # Update state |
| 418 | try: |
| 419 | self.flag = self.context.flags[flag] |
| 420 | except KeyError as e: |
| 421 | # Try fallback to initial/core flag |
| 422 | try: |
| 423 | self.flag = self.initial.flags[flag] |
| 424 | except KeyError: |
| 425 | # If it wasn't in either, raise the original context's |
| 426 | # exception, as that's more useful / correct. |
| 427 | raise e |
| 428 | debug("Moving to flag {!r}".format(self.flag)) |
| 429 | # Bookkeeping for iterable-type flags (where the typical 'value |
| 430 | # non-empty/nondefault -> clearly it got its value already' test is |
| 431 | # insufficient) |
| 432 | self.flag_got_value = False |
| 433 | # Handle boolean flags (which can immediately be updated) |
| 434 | if self.flag and not self.flag.takes_value: |
| 435 | val = not inverse |
| 436 | debug("Marking seen flag {!r} as {}".format(self.flag, val)) |
| 437 | self.flag.value = val |
| 438 | |
| 439 | def see_value(self, value: Any) -> None: |
| 440 | self.check_ambiguity(value) |
no test coverage detected