Skip to content

Commit c51ed84

Browse files
authored
MkDocs improvements for auto-documented code using mkdocstrings (#1409)
1 parent 4ad4d6a commit c51ed84

10 files changed

+67
-67
lines changed

cmd2/ansi.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def clear_screen(clear_type: int = 2) -> str:
165165
2 - clear entire screen
166166
3 - clear entire screen and delete all lines saved in the scrollback buffer
167167
:return: the clear screen string
168-
:raises: ValueError if clear_type is not a valid value
168+
:raises ValueError: if clear_type is not a valid value
169169
"""
170170
if 0 <= clear_type <= 3:
171171
return f"{CSI}{clear_type}J"
@@ -182,7 +182,7 @@ def clear_line(clear_type: int = 2) -> str:
182182
1 - clear from cursor to beginning of the line
183183
2 - clear entire line
184184
:return: the clear line string
185-
:raises: ValueError if clear_type is not a valid value
185+
:raises ValueError: if clear_type is not a valid value
186186
"""
187187
if 0 <= clear_type <= 2:
188188
return f"{CSI}{clear_type}K"
@@ -915,7 +915,7 @@ def __init__(self, r: int, g: int, b: int) -> None:
915915
:param r: integer from 0-255 for the red component of the color
916916
:param g: integer from 0-255 for the green component of the color
917917
:param b: integer from 0-255 for the blue component of the color
918-
:raises: ValueError if r, g, or b is not in the range 0-255
918+
:raises ValueError: if r, g, or b is not in the range 0-255
919919
"""
920920
if any(c < 0 or c > 255 for c in [r, g, b]):
921921
raise ValueError("RGB values must be integers in the range of 0 to 255")
@@ -944,7 +944,7 @@ def __init__(self, r: int, g: int, b: int) -> None:
944944
:param r: integer from 0-255 for the red component of the color
945945
:param g: integer from 0-255 for the green component of the color
946946
:param b: integer from 0-255 for the blue component of the color
947-
:raises: ValueError if r, g, or b is not in the range 0-255
947+
:raises ValueError: if r, g, or b is not in the range 0-255
948948
"""
949949
if any(c < 0 or c > 255 for c in [r, g, b]):
950950
raise ValueError("RGB values must be integers in the range of 0 to 255")
@@ -988,8 +988,8 @@ def style(
988988
:param overline: apply the overline style if True. Defaults to False.
989989
:param strikethrough: apply the strikethrough style if True. Defaults to False.
990990
:param underline: apply the underline style if True. Defaults to False.
991-
:raises: TypeError if fg isn't None or a subclass of FgColor
992-
:raises: TypeError if bg isn't None or a subclass of BgColor
991+
:raises TypeError: if fg isn't None or a subclass of FgColor
992+
:raises TypeError: if bg isn't None or a subclass of BgColor
993993
:return: the stylized string
994994
"""
995995
# List of strings that add style

cmd2/argparse_completer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def complete(
226226
:param cmd_set: if tab completing a command, the CommandSet the command's function belongs to, if applicable.
227227
Defaults to None.
228228
229-
:raises: CompletionError for various types of tab completion errors
229+
:raises CompletionError: for various types of tab completion errors
230230
"""
231231
if not tokens:
232232
return []
@@ -264,7 +264,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
264264
Check if an argument belongs to a mutually exclusive group and either mark that group
265265
as complete or print an error if the group has already been completed
266266
:param arg_action: the action of the argument
267-
:raises: CompletionError if the group is already completed
267+
:raises CompletionError: if the group is already completed
268268
"""
269269
# Check if this action is in a mutually exclusive group
270270
for group in self._parser._mutually_exclusive_groups:
@@ -679,7 +679,7 @@ def _complete_arg(
679679
"""
680680
Tab completion routine for an argparse argument
681681
:return: list of completions
682-
:raises: CompletionError if the completer or choices function this calls raises one
682+
:raises CompletionError: if the completer or choices function this calls raises one
683683
"""
684684
# Check if the arg provides choices to the user
685685
arg_choices: Union[List[str], ChoicesCallable]

cmd2/argparse_custom.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ def __init__(self, value: object, description: str = '', *args: Any) -> None:
300300
:param value: the value being tab completed
301301
:param description: description text to display
302302
:param args: args for str __init__
303-
:param kwargs: kwargs for str __init__
304303
"""
305304
super().__init__(*args)
306305
self.description = description
@@ -473,7 +472,7 @@ def _action_set_choices_callable(self: argparse.Action, choices_callable: Choice
473472
474473
:param self: action being edited
475474
:param choices_callable: the ChoicesCallable instance to use
476-
:raises: TypeError if used on incompatible action type
475+
:raises TypeError: if used on incompatible action type
477476
"""
478477
# Verify consistent use of parameters
479478
if self.choices is not None:
@@ -504,7 +503,7 @@ def _action_set_choices_provider(
504503
505504
:param self: action being edited
506505
:param choices_provider: the choices_provider instance to use
507-
:raises: TypeError if used on incompatible action type
506+
:raises TypeError: if used on incompatible action type
508507
"""
509508
self._set_choices_callable(ChoicesCallable(is_completer=False, to_call=choices_provider)) # type: ignore[attr-defined]
510509

@@ -525,7 +524,7 @@ def _action_set_completer(
525524
526525
:param self: action being edited
527526
:param completer: the completer instance to use
528-
:raises: TypeError if used on incompatible action type
527+
:raises TypeError: if used on incompatible action type
529528
"""
530529
self._set_choices_callable(ChoicesCallable(is_completer=True, to_call=completer)) # type: ignore[attr-defined]
531530

@@ -758,7 +757,7 @@ def _add_argument_wrapper(
758757
See the header of this file for more information
759758
760759
:return: the created argument action
761-
:raises: ValueError on incorrect parameter usage
760+
:raises ValueError: on incorrect parameter usage
762761
"""
763762
# Verify consistent use of arguments
764763
choices_callables = [choices_provider, completer]

cmd2/cmd2.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ def remove_settable(self, name: str) -> None:
11341134
Convenience method for removing a settable parameter from ``self.settables``
11351135
11361136
:param name: name of the settable being removed
1137-
:raises: KeyError if the Settable matches this name
1137+
:raises KeyError: if the Settable matches this name
11381138
"""
11391139
try:
11401140
del self._settables[name]
@@ -2701,8 +2701,8 @@ def _complete_statement(self, line: str, *, orig_rl_history_length: Optional[int
27012701
This is used to assist in combining multiline readline history entries and is only
27022702
populated by cmd2. Defaults to None.
27032703
:return: the completed Statement
2704-
:raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
2705-
:raises: EmptyStatement when the resulting Statement is blank
2704+
:raises Cmd2ShlexError: if a shlex error occurs (e.g. No closing quotation)
2705+
:raises EmptyStatement: when the resulting Statement is blank
27062706
"""
27072707

27082708
def combine_rl_history(statement: Statement) -> None:
@@ -2788,8 +2788,8 @@ def _input_line_to_statement(self, line: str, *, orig_rl_history_length: Optiona
27882788
This is used to assist in combining multiline readline history entries and is only
27892789
populated by cmd2. Defaults to None.
27902790
:return: parsed command line as a Statement
2791-
:raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
2792-
:raises: EmptyStatement when the resulting Statement is blank
2791+
:raises Cmd2ShlexError: if a shlex error occurs (e.g. No closing quotation)
2792+
:raises EmptyStatement: when the resulting Statement is blank
27932793
"""
27942794
used_macros = []
27952795
orig_line = None
@@ -2879,7 +2879,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
28792879
28802880
:param statement: a parsed statement from the user
28812881
:return: A bool telling if an error occurred and a utils.RedirectionSavedState object
2882-
:raises: RedirectionError if an error occurs trying to pipe or redirect
2882+
:raises RedirectionError: if an error occurs trying to pipe or redirect
28832883
"""
28842884
import io
28852885
import subprocess
@@ -3135,7 +3135,7 @@ def read_input(
31353135
:param parser: an argument parser which supports the tab completion of multiple arguments
31363136
31373137
:return: the line read from stdin with all trailing new lines removed
3138-
:raises: any exceptions raised by input() and stdin.readline()
3138+
:raises Exception: any exceptions raised by input() and stdin.readline()
31393139
"""
31403140
readline_configured = False
31413141
saved_completer: Optional[CompleterFunc] = None
@@ -3260,7 +3260,7 @@ def _read_command_line(self, prompt: str) -> str:
32603260
32613261
:param prompt: prompt to display to user
32623262
:return: command line text of 'eof' if an EOFError was caught
3263-
:raises: whatever exceptions are raised by input() except for EOFError
3263+
:raises Exception: whatever exceptions are raised by input() except for EOFError
32643264
"""
32653265
try:
32663266
# Wrap in try since terminal_lock may not be locked
@@ -5080,7 +5080,7 @@ def run_editor(self, file_path: Optional[str] = None) -> None:
50805080
Run a text editor and optionally open a file with it
50815081
50825082
:param file_path: optional path of the file to edit. Defaults to None.
5083-
:raises: EnvironmentError if self.editor is not set
5083+
:raises EnvironmentError: if self.editor is not set
50845084
"""
50855085
if not self.editor:
50865086
raise EnvironmentError("Please use 'set editor' to specify your text editing program of choice.")
@@ -5515,9 +5515,9 @@ def _report_disabled_command_usage(self, *_args: Any, message_to_print: str, **_
55155515
"""
55165516
Report when a disabled command has been run or had help called on it
55175517
5518-
:param args: not used
5518+
:param _args: not used
55195519
:param message_to_print: the message reporting that the command is disabled
5520-
:param kwargs: not used
5520+
:param _kwargs: not used
55215521
"""
55225522
# Set apply_style to False so message_to_print's style is not overridden
55235523
self.perror(message_to_print, apply_style=False)

cmd2/command_definition.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _cmd(self) -> 'cmd2.Cmd':
114114
Override this property if you need to change its return type to a
115115
child class of Cmd.
116116
117-
:raises: CommandSetRegistrationError if CommandSet is not registered.
117+
:raises CommandSetRegistrationError: if CommandSet is not registered.
118118
"""
119119
if self.__cmd_internal is None:
120120
raise CommandSetRegistrationError('This CommandSet is not registered')
@@ -127,7 +127,7 @@ def on_register(self, cmd: 'cmd2.Cmd') -> None:
127127
requiring access to the Cmd object (e.g. configure commands and their parsers based on CLI state data).
128128
129129
:param cmd: The cmd2 main application
130-
:raises: CommandSetRegistrationError if CommandSet is already registered.
130+
:raises CommandSetRegistrationError: if CommandSet is already registered.
131131
"""
132132
if self.__cmd_internal is None:
133133
self.__cmd_internal = cmd
@@ -185,7 +185,7 @@ def remove_settable(self, name: str) -> None:
185185
Convenience method for removing a settable parameter from the CommandSet
186186
187187
:param name: name of the settable being removed
188-
:raises: KeyError if the Settable matches this name
188+
:raises KeyError: if the Settable matches this name
189189
"""
190190
try:
191191
del self._settables[name]

cmd2/decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def cmd_wrapper(*args: Any, **kwargs: Dict[str, Any]) -> Optional[bool]:
354354
contiguously somewhere in the list
355355
:param kwargs: any keyword arguments being passed to command function
356356
:return: return value of command function
357-
:raises: Cmd2ArgparseError if argparse has error parsing command line
357+
:raises Cmd2ArgparseError: if argparse has error parsing command line
358358
"""
359359
cmd2_app, statement_arg = _parse_positionals(args)
360360
statement, parsed_arglist = cmd2_app.statement_parser.get_command_arg_list(

cmd2/parsing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def tokenize(self, line: str) -> List[str]:
376376
377377
:param line: the command line being lexed
378378
:return: A list of tokens
379-
:raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
379+
:raises Cmd2ShlexError: if a shlex error occurs (e.g. No closing quotation)
380380
"""
381381

382382
# expand shortcuts and aliases
@@ -404,7 +404,7 @@ def parse(self, line: str) -> Statement:
404404
405405
:param line: the command line being parsed
406406
:return: a new [cmd2.parsing.Statement][] object
407-
:raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
407+
:raises Cmd2ShlexError: if a shlex error occurs (e.g. No closing quotation)
408408
"""
409409

410410
# handle the special case/hardcoded terminator of a blank line

cmd2/table_creator.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def __init__(
9292
(defaults to True)
9393
:param max_data_lines: maximum lines allowed in a data cell. If line count exceeds this, then the final
9494
line displayed will be truncated with an ellipsis. (defaults to INFINITY)
95-
:raises: ValueError if width is less than 1
96-
:raises: ValueError if max_data_lines is less than 1
95+
:raises ValueError: if width is less than 1
96+
:raises ValueError: if max_data_lines is less than 1
9797
"""
9898
self.header = header
9999

@@ -138,7 +138,7 @@ def __init__(self, cols: Sequence[Column], *, tab_width: int = 4) -> None:
138138
:param cols: column definitions for this table
139139
:param tab_width: all tabs will be replaced with this many spaces. If a row's fill_char is a tab,
140140
then it will be converted to one space.
141-
:raises: ValueError if tab_width is less than 1
141+
:raises ValueError: if tab_width is less than 1
142142
"""
143143
if tab_width < 1:
144144
raise ValueError("Tab width cannot be less than 1")
@@ -443,9 +443,9 @@ def generate_row(
443443
:param post_line: string to print after each line of a row. This can be used for padding after
444444
the last cell's text and a right row border. (Defaults to blank)
445445
:return: row string
446-
:raises: ValueError if row_data isn't the same length as self.cols
447-
:raises: TypeError if fill_char is more than one character (not including ANSI style sequences)
448-
:raises: ValueError if fill_char, pre_line, inter_cell, or post_line contains an unprintable
446+
:raises ValueError: if row_data isn't the same length as self.cols
447+
:raises TypeError: if fill_char is more than one character (not including ANSI style sequences)
448+
:raises ValueError: if fill_char, pre_line, inter_cell, or post_line contains an unprintable
449449
character like a newline
450450
"""
451451

@@ -570,10 +570,10 @@ def __init__(
570570
want a divider row. Defaults to dash. (Cannot be a line breaking character)
571571
:param header_bg: optional background color for header cells (defaults to None)
572572
:param data_bg: optional background color for data cells (defaults to None)
573-
:raises: ValueError if tab_width is less than 1
574-
:raises: ValueError if column_spacing is less than 0
575-
:raises: TypeError if divider_char is longer than one character
576-
:raises: ValueError if divider_char is an unprintable character
573+
:raises ValueError: if tab_width is less than 1
574+
:raises ValueError: if column_spacing is less than 0
575+
:raises TypeError: if divider_char is longer than one character
576+
:raises ValueError: if divider_char is an unprintable character
577577
"""
578578
super().__init__(cols, tab_width=tab_width)
579579

@@ -626,8 +626,8 @@ def base_width(cls, num_cols: int, *, column_spacing: int = 2) -> int:
626626
:param num_cols: how many columns the table will have
627627
:param column_spacing: how many spaces to place between columns. Defaults to 2.
628628
:return: base width
629-
:raises: ValueError if column_spacing is less than 0
630-
:raises: ValueError if num_cols is less than 1
629+
:raises ValueError: if column_spacing is less than 0
630+
:raises ValueError: if num_cols is less than 1
631631
"""
632632
if num_cols < 1:
633633
raise ValueError("Column count cannot be less than 1")
@@ -685,7 +685,7 @@ def generate_data_row(self, row_data: Sequence[Any]) -> str:
685685
686686
:param row_data: data with an entry for each column in the row
687687
:return: data row string
688-
:raises: ValueError if row_data isn't the same length as self.cols
688+
:raises ValueError: if row_data isn't the same length as self.cols
689689
"""
690690
if len(row_data) != len(self.cols):
691691
raise ValueError("Length of row_data must match length of cols")
@@ -712,7 +712,7 @@ def generate_table(self, table_data: Sequence[Sequence[Any]], *, include_header:
712712
:param include_header: If True, then a header will be included at top of table. (Defaults to True)
713713
:param row_spacing: A number 0 or greater specifying how many blank lines to place between
714714
each row (Defaults to 1)
715-
:raises: ValueError if row_spacing is less than 0
715+
:raises ValueError: if row_spacing is less than 0
716716
"""
717717
if row_spacing < 0:
718718
raise ValueError("Row spacing cannot be less than 0")
@@ -771,8 +771,8 @@ def __init__(
771771
:param border_bg: optional background color for borders (defaults to None)
772772
:param header_bg: optional background color for header cells (defaults to None)
773773
:param data_bg: optional background color for data cells (defaults to None)
774-
:raises: ValueError if tab_width is less than 1
775-
:raises: ValueError if padding is less than 0
774+
:raises ValueError: if tab_width is less than 1
775+
:raises ValueError: if padding is less than 0
776776
"""
777777
super().__init__(cols, tab_width=tab_width)
778778
self.empty_data = [EMPTY] * len(self.cols)
@@ -827,7 +827,7 @@ def base_width(cls, num_cols: int, *, column_borders: bool = True, padding: int
827827
:param column_borders: if True, borders between columns will be included in the calculation (Defaults to True)
828828
:param padding: number of spaces between text and left/right borders of cell
829829
:return: base width
830-
:raises: ValueError if num_cols is less than 1
830+
:raises ValueError: if num_cols is less than 1
831831
"""
832832
if num_cols < 1:
833833
raise ValueError("Column count cannot be less than 1")
@@ -976,7 +976,7 @@ def generate_data_row(self, row_data: Sequence[Any]) -> str:
976976
977977
:param row_data: data with an entry for each column in the row
978978
:return: data row string
979-
:raises: ValueError if row_data isn't the same length as self.cols
979+
:raises ValueError: if row_data isn't the same length as self.cols
980980
"""
981981
if len(row_data) != len(self.cols):
982982
raise ValueError("Length of row_data must match length of cols")
@@ -1077,8 +1077,8 @@ def __init__(
10771077
:param header_bg: optional background color for header cells (defaults to None)
10781078
:param odd_bg: optional background color for odd numbered data rows (defaults to None)
10791079
:param even_bg: optional background color for even numbered data rows (defaults to StdBg.DARK_GRAY)
1080-
:raises: ValueError if tab_width is less than 1
1081-
:raises: ValueError if padding is less than 0
1080+
:raises ValueError: if tab_width is less than 1
1081+
:raises ValueError: if padding is less than 0
10821082
"""
10831083
super().__init__(
10841084
cols,

0 commit comments

Comments
 (0)