Skip to content

Commit b5a8eeb

Browse files
committed
Applied automated pydocstyle refactoring outside of test directories
1 parent abb8579 commit b5a8eeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+451
-442
lines changed

cmd2/ansi.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828

2929

3030
class AllowStyle(Enum):
31-
"""Values for ``cmd2.ansi.allow_style``"""
31+
"""Values for ``cmd2.ansi.allow_style``."""
3232

3333
ALWAYS = 'Always' # Always output ANSI style sequences
3434
NEVER = 'Never' # Remove ANSI style sequences from all output
3535
TERMINAL = 'Terminal' # Remove ANSI style sequences if the output is not going to the terminal
3636

3737
def __str__(self) -> str:
38-
"""Return value instead of enum name for printing in cmd2's set command"""
38+
"""Return value instead of enum name for printing in cmd2's set command."""
3939
return str(self.value)
4040

4141
def __repr__(self) -> str:
42-
"""Return quoted value instead of enum description for printing in cmd2's set command"""
42+
"""Return quoted value instead of enum description for printing in cmd2's set command."""
4343
return repr(self.value)
4444

4545

@@ -124,7 +124,7 @@ def widest_line(text: str) -> int:
124124

125125

126126
def style_aware_write(fileobj: IO[str], msg: str) -> None:
127-
"""Write a string to a fileobject and strip its ANSI style sequences if required by allow_style setting
127+
"""Write a string to a fileobject and strip its ANSI style sequences if required by allow_style setting.
128128
129129
:param fileobj: the file object being written to
130130
:param msg: the string being written
@@ -183,63 +183,63 @@ def clear_line(clear_type: int = 2) -> str:
183183
# Base classes which are not intended to be used directly
184184
####################################################################################
185185
class AnsiSequence:
186-
"""Base class to create ANSI sequence strings"""
186+
"""Base class to create ANSI sequence strings."""
187187

188188
def __add__(self, other: Any) -> str:
189189
"""Support building an ANSI sequence string when self is the left operand
190-
e.g. Fg.LIGHT_MAGENTA + "hello"
190+
e.g. Fg.LIGHT_MAGENTA + "hello".
191191
"""
192192
return str(self) + str(other)
193193

194194
def __radd__(self, other: Any) -> str:
195195
"""Support building an ANSI sequence string when self is the right operand
196-
e.g. "hello" + Fg.RESET
196+
e.g. "hello" + Fg.RESET.
197197
"""
198198
return str(other) + str(self)
199199

200200

201201
class FgColor(AnsiSequence):
202-
"""Base class for ANSI Sequences which set foreground text color"""
202+
"""Base class for ANSI Sequences which set foreground text color."""
203203

204204

205205
class BgColor(AnsiSequence):
206-
"""Base class for ANSI Sequences which set background text color"""
206+
"""Base class for ANSI Sequences which set background text color."""
207207

208208

209209
####################################################################################
210210
# Implementations intended for direct use
211211
####################################################################################
212212
class Cursor:
213-
"""Create ANSI sequences to alter the cursor position"""
213+
"""Create ANSI sequences to alter the cursor position."""
214214

215215
@staticmethod
216216
def UP(count: int = 1) -> str:
217-
"""Move the cursor up a specified amount of lines (Defaults to 1)"""
217+
"""Move the cursor up a specified amount of lines (Defaults to 1)."""
218218
return f"{CSI}{count}A"
219219

220220
@staticmethod
221221
def DOWN(count: int = 1) -> str:
222-
"""Move the cursor down a specified amount of lines (Defaults to 1)"""
222+
"""Move the cursor down a specified amount of lines (Defaults to 1)."""
223223
return f"{CSI}{count}B"
224224

225225
@staticmethod
226226
def FORWARD(count: int = 1) -> str:
227-
"""Move the cursor forward a specified amount of lines (Defaults to 1)"""
227+
"""Move the cursor forward a specified amount of lines (Defaults to 1)."""
228228
return f"{CSI}{count}C"
229229

230230
@staticmethod
231231
def BACK(count: int = 1) -> str:
232-
"""Move the cursor back a specified amount of lines (Defaults to 1)"""
232+
"""Move the cursor back a specified amount of lines (Defaults to 1)."""
233233
return f"{CSI}{count}D"
234234

235235
@staticmethod
236236
def SET_POS(x: int, y: int) -> str:
237-
"""Set the cursor position to coordinates which are 1-based"""
237+
"""Set the cursor position to coordinates which are 1-based."""
238238
return f"{CSI}{y};{x}H"
239239

240240

241241
class TextStyle(AnsiSequence, Enum):
242-
"""Create text style ANSI sequences"""
242+
"""Create text style ANSI sequences."""
243243

244244
# Resets all styles and colors of text
245245
RESET_ALL = 0
@@ -264,7 +264,7 @@ class TextStyle(AnsiSequence, Enum):
264264
def __str__(self) -> str:
265265
"""Return ANSI text style sequence instead of enum name
266266
This is helpful when using a TextStyle in an f-string or format() call
267-
e.g. my_str = f"{TextStyle.UNDERLINE_ENABLE}hello{TextStyle.UNDERLINE_DISABLE}"
267+
e.g. my_str = f"{TextStyle.UNDERLINE_ENABLE}hello{TextStyle.UNDERLINE_DISABLE}".
268268
"""
269269
return f"{CSI}{self.value}m"
270270

@@ -297,7 +297,7 @@ class Fg(FgColor, Enum):
297297
def __str__(self) -> str:
298298
"""Return ANSI color sequence instead of enum name
299299
This is helpful when using an Fg in an f-string or format() call
300-
e.g. my_str = f"{Fg.BLUE}hello{Fg.RESET}"
300+
e.g. my_str = f"{Fg.BLUE}hello{Fg.RESET}".
301301
"""
302302
return f"{CSI}{self.value}m"
303303

@@ -330,7 +330,7 @@ class Bg(BgColor, Enum):
330330
def __str__(self) -> str:
331331
"""Return ANSI color sequence instead of enum name
332332
This is helpful when using a Bg in an f-string or format() call
333-
e.g. my_str = f"{Bg.BLACK}hello{Bg.RESET}"
333+
e.g. my_str = f"{Bg.BLACK}hello{Bg.RESET}".
334334
"""
335335
return f"{CSI}{self.value}m"
336336

@@ -601,7 +601,7 @@ class EightBitFg(FgColor, Enum):
601601
def __str__(self) -> str:
602602
"""Return ANSI color sequence instead of enum name
603603
This is helpful when using an EightBitFg in an f-string or format() call
604-
e.g. my_str = f"{EightBitFg.SLATE_BLUE_1}hello{Fg.RESET}"
604+
e.g. my_str = f"{EightBitFg.SLATE_BLUE_1}hello{Fg.RESET}".
605605
"""
606606
return f"{CSI}38;5;{self.value}m"
607607

@@ -872,7 +872,7 @@ class EightBitBg(BgColor, Enum):
872872
def __str__(self) -> str:
873873
"""Return ANSI color sequence instead of enum name
874874
This is helpful when using an EightBitBg in an f-string or format() call
875-
e.g. my_str = f"{EightBitBg.KHAKI_3}hello{Bg.RESET}"
875+
e.g. my_str = f"{EightBitBg.KHAKI_3}hello{Bg.RESET}".
876876
"""
877877
return f"{CSI}48;5;{self.value}m"
878878

@@ -883,7 +883,7 @@ class RgbFg(FgColor):
883883
"""
884884

885885
def __init__(self, r: int, g: int, b: int) -> None:
886-
"""RgbFg initializer
886+
"""RgbFg initializer.
887887
888888
:param r: integer from 0-255 for the red component of the color
889889
:param g: integer from 0-255 for the green component of the color
@@ -898,7 +898,7 @@ def __init__(self, r: int, g: int, b: int) -> None:
898898
def __str__(self) -> str:
899899
"""Return ANSI color sequence instead of enum name
900900
This is helpful when using an RgbFg in an f-string or format() call
901-
e.g. my_str = f"{RgbFg(0, 55, 100)}hello{Fg.RESET}"
901+
e.g. my_str = f"{RgbFg(0, 55, 100)}hello{Fg.RESET}".
902902
"""
903903
return self._sequence
904904

@@ -909,7 +909,7 @@ class RgbBg(BgColor):
909909
"""
910910

911911
def __init__(self, r: int, g: int, b: int) -> None:
912-
"""RgbBg initializer
912+
"""RgbBg initializer.
913913
914914
:param r: integer from 0-255 for the red component of the color
915915
:param g: integer from 0-255 for the green component of the color
@@ -924,7 +924,7 @@ def __init__(self, r: int, g: int, b: int) -> None:
924924
def __str__(self) -> str:
925925
"""Return ANSI color sequence instead of enum name
926926
This is helpful when using an RgbBg in an f-string or format() call
927-
e.g. my_str = f"{RgbBg(100, 255, 27)}hello{Bg.RESET}"
927+
e.g. my_str = f"{RgbBg(100, 255, 27)}hello{Bg.RESET}".
928928
"""
929929
return self._sequence
930930

cmd2/argparse_completer.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656

5757
def _build_hint(parser: argparse.ArgumentParser, arg_action: argparse.Action) -> str:
58-
"""Build tab completion hint for a given argument"""
58+
"""Build tab completion hint for a given argument."""
5959
# Check if hinting is disabled for this argument
6060
suppress_hint = arg_action.get_suppress_tab_hint() # type: ignore[attr-defined]
6161
if suppress_hint or arg_action.help == argparse.SUPPRESS:
@@ -70,7 +70,7 @@ def _build_hint(parser: argparse.ArgumentParser, arg_action: argparse.Action) ->
7070

7171

7272
def _single_prefix_char(token: str, parser: argparse.ArgumentParser) -> bool:
73-
"""Returns if a token is just a single flag prefix character"""
73+
"""Returns if a token is just a single flag prefix character."""
7474
return len(token) == 1 and token[0] in parser.prefix_chars
7575

7676

@@ -101,7 +101,7 @@ def _looks_like_flag(token: str, parser: argparse.ArgumentParser) -> bool:
101101

102102

103103
class _ArgumentState:
104-
"""Keeps state of an argument being parsed"""
104+
"""Keeps state of an argument being parsed."""
105105

106106
def __init__(self, arg_action: argparse.Action) -> None:
107107
self.action = arg_action
@@ -137,7 +137,7 @@ def __init__(self, arg_action: argparse.Action) -> None:
137137
class _UnfinishedFlagError(CompletionError):
138138
def __init__(self, flag_arg_state: _ArgumentState) -> None:
139139
"""CompletionError which occurs when the user has not finished the current flag
140-
:param flag_arg_state: information about the unfinished flag action
140+
:param flag_arg_state: information about the unfinished flag action.
141141
"""
142142
arg = f'{argparse._get_action_name(flag_arg_state.action)}'
143143
err = f'{generate_range_error(cast(int, flag_arg_state.min), cast(Union[int, float], flag_arg_state.max))}'
@@ -150,19 +150,19 @@ def __init__(self, parser: argparse.ArgumentParser, arg_action: argparse.Action)
150150
"""CompletionError which occurs when there are no results. If hinting is allowed, then its message will
151151
be a hint about the argument being tab completed.
152152
:param parser: ArgumentParser instance which owns the action being tab completed
153-
:param arg_action: action being tab completed
153+
:param arg_action: action being tab completed.
154154
"""
155155
# Set apply_style to False because we don't want hints to look like errors
156156
super().__init__(_build_hint(parser, arg_action), apply_style=False)
157157

158158

159159
class ArgparseCompleter:
160-
"""Automatic command line tab completion based on argparse parameters"""
160+
"""Automatic command line tab completion based on argparse parameters."""
161161

162162
def __init__(
163163
self, parser: argparse.ArgumentParser, cmd2_app: 'Cmd', *, parent_tokens: Optional[dict[str, list[str]]] = None
164164
) -> None:
165-
"""Create an ArgparseCompleter
165+
"""Create an ArgparseCompleter.
166166
167167
:param parser: ArgumentParser instance
168168
:param cmd2_app: reference to the Cmd2 application that owns this ArgparseCompleter
@@ -202,7 +202,7 @@ def __init__(
202202
def complete(
203203
self, text: str, line: str, begidx: int, endidx: int, tokens: list[str], *, cmd_set: Optional[CommandSet] = None
204204
) -> list[str]:
205-
"""Complete text using argparse metadata
205+
"""Complete text using argparse metadata.
206206
207207
:param text: the string prefix we are attempting to match (all matches must begin with it)
208208
:param line: the current input line with leading whitespace removed
@@ -240,7 +240,7 @@ def complete(
240240
completed_mutex_groups: dict[argparse._MutuallyExclusiveGroup, argparse.Action] = {}
241241

242242
def consume_argument(arg_state: _ArgumentState) -> None:
243-
"""Consuming token as an argument"""
243+
"""Consuming token as an argument."""
244244
arg_state.count += 1
245245
consumed_arg_values.setdefault(arg_state.action.dest, [])
246246
consumed_arg_values[arg_state.action.dest].append(token)
@@ -249,7 +249,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
249249
"""Check if an argument belongs to a mutually exclusive group and either mark that group
250250
as complete or print an error if the group has already been completed
251251
:param arg_action: the action of the argument
252-
:raises CompletionError: if the group is already completed
252+
:raises CompletionError: if the group is already completed.
253253
"""
254254
# Check if this action is in a mutually exclusive group
255255
for group in self._parser._mutually_exclusive_groups:
@@ -490,7 +490,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
490490
return completion_results
491491

492492
def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, matched_flags: list[str]) -> list[str]:
493-
"""Tab completion routine for a parsers unused flags"""
493+
"""Tab completion routine for a parsers unused flags."""
494494
# Build a list of flags that can be tab completed
495495
match_against = []
496496

@@ -523,7 +523,7 @@ def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, matche
523523
return matches
524524

525525
def _format_completions(self, arg_state: _ArgumentState, completions: Union[list[str], list[CompletionItem]]) -> list[str]:
526-
"""Format CompletionItems into hint table"""
526+
"""Format CompletionItems into hint table."""
527527
# Nothing to do if we don't have at least 2 completions which are all CompletionItems
528528
if len(completions) < 2 or not all(isinstance(c, CompletionItem) for c in completions):
529529
return cast(list[str], completions)
@@ -605,7 +605,7 @@ def complete_subcommand_help(self, text: str, line: str, begidx: int, endidx: in
605605
:param begidx: the beginning index of the prefix text
606606
:param endidx: the ending index of the prefix text
607607
:param tokens: arguments passed to command/subcommand
608-
:return: list of subcommand completions
608+
:return: list of subcommand completions.
609609
"""
610610
# If our parser has subcommands, we must examine the tokens and check if they are subcommands
611611
# If so, we will let the subcommand's parser handle the rest of the tokens via another ArgparseCompleter.
@@ -626,7 +626,7 @@ def complete_subcommand_help(self, text: str, line: str, begidx: int, endidx: in
626626
def format_help(self, tokens: list[str]) -> str:
627627
"""Supports cmd2's help command in the retrieval of help text
628628
:param tokens: arguments passed to help command
629-
:return: help text of the command being queried
629+
:return: help text of the command being queried.
630630
"""
631631
# If our parser has subcommands, we must examine the tokens and check if they are subcommands
632632
# If so, we will let the subcommand's parser handle the rest of the tokens via another ArgparseCompleter.
@@ -654,7 +654,7 @@ def _complete_arg(
654654
) -> list[str]:
655655
"""Tab completion routine for an argparse argument
656656
:return: list of completions
657-
:raises CompletionError: if the completer or choices function this calls raises one
657+
:raises CompletionError: if the completer or choices function this calls raises one.
658658
"""
659659
# Check if the arg provides choices to the user
660660
arg_choices: Union[list[str], ChoicesCallable]

0 commit comments

Comments
 (0)