Skip to content

Commit

Permalink
Add some asserts for things that are always true
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Feb 26, 2023
1 parent 78b5158 commit d49d1bd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pydocstringformatter/_configuration/boolean_option_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ def __init__(
# Non-argparse changes
assert help, "All BooleanOptionalAction's should have a help message."

# Rest of implementation directly copied from argparse
# Rest of implementation directly copied from argparse, expect for the asserts
_option_strings = []
for option_string in option_strings:
_option_strings.append(option_string)

if option_string.startswith("--"):
option_string = "--no-" + option_string[2:]
_option_strings.append(option_string)
assert option_string.startswith("--")
option_string = "--no-" + option_string[2:]
_option_strings.append(option_string)

if help is not None and default is not None:
help += " (default: %(default)s)"
assert help is not None and default is not None
help += " (default: %(default)s)"

super().__init__(
option_strings=_option_strings,
Expand All @@ -63,8 +63,8 @@ def __call__(
"BooleanOptionalAction can't be a positional argument. "
f"Something is wrong with {self.option_strings[0]}"
)
if option_string in self.option_strings:
setattr(namespace, self.dest, not option_string.startswith("--no-"))
assert option_string in self.option_strings
setattr(namespace, self.dest, not option_string.startswith("--no-"))

def format_usage(self) -> str:
"""Return usage string."""
Expand Down

0 comments on commit d49d1bd

Please sign in to comment.