Skip to content

Commit 881a985

Browse files
committed
Automatically applied return type of None for functions/methods that don't return anything
1 parent 916802d commit 881a985

Some content is hidden

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

62 files changed

+1064
-1060
lines changed

examples/alias_startup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
class AliasAndStartup(cmd2.Cmd):
1313
"""Example cmd2 application where we create commands that just print the arguments they are called with."""
1414

15-
def __init__(self):
15+
def __init__(self) -> None:
1616
alias_script = os.path.join(os.path.dirname(__file__), '.cmd2rc')
1717
super().__init__(startup_script=alias_script)
1818

19-
def do_nothing(self, args):
19+
def do_nothing(self, args) -> None:
2020
"""This command does nothing and produces no output."""
2121

2222

examples/arg_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class ArgparsingApp(cmd2.Cmd):
11-
def __init__(self):
11+
def __init__(self) -> None:
1212
super().__init__(include_ipy=True)
1313
self.intro = 'cmd2 has awesome decorators to make it easy to use Argparse to parse command arguments'
1414

examples/arg_print.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515
class ArgumentAndOptionPrinter(cmd2.Cmd):
1616
"""Example cmd2 application where we create commands that just print the arguments they are called with."""
1717

18-
def __init__(self):
18+
def __init__(self) -> None:
1919
# Create command shortcuts which are typically 1 character abbreviations which can be used in place of a command
2020
shortcuts = dict(cmd2.DEFAULT_SHORTCUTS)
2121
shortcuts.update({'$': 'aprint', '%': 'oprint'})
2222
super().__init__(shortcuts=shortcuts)
2323

24-
def do_aprint(self, statement):
24+
def do_aprint(self, statement) -> None:
2525
"""Print the argument string this basic command is called with."""
2626
self.poutput(f'aprint was called with argument: {statement!r}')
2727
self.poutput(f'statement.raw = {statement.raw!r}')
2828
self.poutput(f'statement.argv = {statement.argv!r}')
2929
self.poutput(f'statement.command = {statement.command!r}')
3030

3131
@cmd2.with_argument_list
32-
def do_lprint(self, arglist):
32+
def do_lprint(self, arglist) -> None:
3333
"""Print the argument list this basic command is called with."""
3434
self.poutput(f'lprint was called with the following list of arguments: {arglist!r}')
3535

3636
@cmd2.with_argument_list(preserve_quotes=True)
37-
def do_rprint(self, arglist):
37+
def do_rprint(self, arglist) -> None:
3838
"""Print the argument list this basic command is called with (with quotes preserved)."""
3939
self.poutput(f'rprint was called with the following list of arguments: {arglist!r}')
4040

@@ -45,7 +45,7 @@ def do_rprint(self, arglist):
4545
oprint_parser.add_argument('words', nargs='+', help='words to print')
4646

4747
@cmd2.with_argparser(oprint_parser)
48-
def do_oprint(self, args):
48+
def do_oprint(self, args) -> None:
4949
"""Print the options and argument list this options command was called with."""
5050
self.poutput(f'oprint was called with the following\n\toptions: {args!r}')
5151

@@ -55,7 +55,7 @@ def do_oprint(self, args):
5555
pprint_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
5656

5757
@cmd2.with_argparser(pprint_parser, with_unknown_args=True)
58-
def do_pprint(self, args, unknown):
58+
def do_pprint(self, args, unknown) -> None:
5959
"""Print the options and argument list this options command was called with."""
6060
self.poutput(f'oprint was called with the following\n\toptions: {args!r}\n\targuments: {unknown}')
6161

examples/argparse_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class ArgparseCompletion(Cmd):
22-
def __init__(self, *args, **kwargs):
22+
def __init__(self, *args, **kwargs) -> None:
2323
super().__init__(*args, **kwargs)
2424
self.sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball']
2525

examples/async_printing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _postloop_hook(self) -> None:
6868
if self._alerter_thread.is_alive():
6969
self._alerter_thread.join()
7070

71-
def do_start_alerts(self, _):
71+
def do_start_alerts(self, _) -> None:
7272
"""Starts the alerter thread"""
7373
if self._alerter_thread.is_alive():
7474
print("The alert thread is already started")
@@ -77,7 +77,7 @@ def do_start_alerts(self, _):
7777
self._alerter_thread = threading.Thread(name='alerter', target=self._alerter_thread_func)
7878
self._alerter_thread.start()
7979

80-
def do_stop_alerts(self, _):
80+
def do_stop_alerts(self, _) -> None:
8181
"""Stops the alerter thread"""
8282
self._stop_event.set()
8383
if self._alerter_thread.is_alive():

examples/basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class BasicApp(cmd2.Cmd):
2020
CUSTOM_CATEGORY = 'My Custom Commands'
2121

22-
def __init__(self):
22+
def __init__(self) -> None:
2323
super().__init__(
2424
multiline_commands=['echo'],
2525
persistent_history_file='cmd2_history.dat',
@@ -36,12 +36,12 @@ def __init__(self):
3636
self.default_category = 'cmd2 Built-in Commands'
3737

3838
@cmd2.with_category(CUSTOM_CATEGORY)
39-
def do_intro(self, _):
39+
def do_intro(self, _) -> None:
4040
"""Display the intro banner"""
4141
self.poutput(self.intro)
4242

4343
@cmd2.with_category(CUSTOM_CATEGORY)
44-
def do_echo(self, arg):
44+
def do_echo(self, arg) -> None:
4545
"""Example of a multiline command"""
4646
self.poutput(arg)
4747

examples/basic_completion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232

3333
class BasicCompletion(cmd2.Cmd):
34-
def __init__(self, *args, **kwargs):
34+
def __init__(self, *args, **kwargs) -> None:
3535
super().__init__(*args, **kwargs)
3636

37-
def do_flag_based(self, statement: cmd2.Statement):
37+
def do_flag_based(self, statement: cmd2.Statement) -> None:
3838
"""Tab completes arguments based on a preceding flag using flag_based_complete
3939
-f, --food [completes food items]
4040
-s, --sport [completes sports]
@@ -58,7 +58,7 @@ def complete_flag_based(self, text, line, begidx, endidx) -> list[str]:
5858

5959
return self.flag_based_complete(text, line, begidx, endidx, flag_dict=flag_dict)
6060

61-
def do_index_based(self, statement: cmd2.Statement):
61+
def do_index_based(self, statement: cmd2.Statement) -> None:
6262
"""Tab completes first 3 arguments using index_based_complete"""
6363
self.poutput(f"Args: {statement.args}")
6464

@@ -72,14 +72,14 @@ def complete_index_based(self, text, line, begidx, endidx) -> list[str]:
7272

7373
return self.index_based_complete(text, line, begidx, endidx, index_dict=index_dict)
7474

75-
def do_delimiter_complete(self, statement: cmd2.Statement):
75+
def do_delimiter_complete(self, statement: cmd2.Statement) -> None:
7676
"""Tab completes files from a list using delimiter_complete"""
7777
self.poutput(f"Args: {statement.args}")
7878

7979
# Use a partialmethod to set arguments to delimiter_complete
8080
complete_delimiter_complete = functools.partialmethod(cmd2.Cmd.delimiter_complete, match_against=file_strs, delimiter='/')
8181

82-
def do_raise_error(self, statement: cmd2.Statement):
82+
def do_raise_error(self, statement: cmd2.Statement) -> None:
8383
"""Demonstrates effect of raising CompletionError"""
8484
self.poutput(f"Args: {statement.args}")
8585

examples/cmd_as_argument.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CmdLineApp(cmd2.Cmd):
2626
MUMBLE_FIRST = ['so', 'like', 'well']
2727
MUMBLE_LAST = ['right?']
2828

29-
def __init__(self):
29+
def __init__(self) -> None:
3030
shortcuts = dict(cmd2.DEFAULT_SHORTCUTS)
3131
shortcuts.update({'&': 'speak'})
3232
# Set include_ipy to True to enable the "ipy" command which runs an interactive IPython shell
@@ -44,7 +44,7 @@ def __init__(self):
4444
speak_parser.add_argument('words', nargs='+', help='words to say')
4545

4646
@cmd2.with_argparser(speak_parser)
47-
def do_speak(self, args):
47+
def do_speak(self, args) -> None:
4848
"""Repeats what you tell me to."""
4949
words = []
5050
for word in args.words:
@@ -66,7 +66,7 @@ def do_speak(self, args):
6666
mumble_parser.add_argument('words', nargs='+', help='words to say')
6767

6868
@cmd2.with_argparser(mumble_parser)
69-
def do_mumble(self, args):
69+
def do_mumble(self, args) -> None:
7070
"""Mumbles what you tell me to."""
7171
repetitions = args.repeat or 1
7272
for i in range(min(repetitions, self.maxrepeats)):

examples/colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
class CmdLineApp(cmd2.Cmd):
3737
"""Example cmd2 application demonstrating colorized output."""
3838

39-
def __init__(self):
39+
def __init__(self) -> None:
4040
# Set include_ipy to True to enable the "ipy" command which runs an interactive IPython shell
4141
super().__init__(include_ipy=True)
4242

@@ -58,7 +58,7 @@ def __init__(self):
5858
speak_parser.add_argument('words', nargs='+', help='words to say')
5959

6060
@cmd2.with_argparser(speak_parser)
61-
def do_speak(self, args):
61+
def do_speak(self, args) -> None:
6262
"""Repeats what you tell me to."""
6363
words = []
6464
for word in args.words:
@@ -78,7 +78,7 @@ def do_speak(self, args):
7878
# .poutput handles newlines, and accommodates output redirection too
7979
self.poutput(output_str)
8080

81-
def do_timetravel(self, _):
81+
def do_timetravel(self, _) -> None:
8282
"""A command which always generates an error message, to demonstrate custom error colors"""
8383
self.perror('Mr. Fusion failed to start. Could not energize flux capacitor.')
8484

examples/decorator_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class CmdLineApp(cmd2.Cmd):
1919
"""Example cmd2 application."""
2020

21-
def __init__(self, ip_addr=None, port=None, transcript_files=None):
21+
def __init__(self, ip_addr=None, port=None, transcript_files=None) -> None:
2222
shortcuts = dict(cmd2.DEFAULT_SHORTCUTS)
2323
shortcuts.update({'&': 'speak'})
2424
super().__init__(transcript_files=transcript_files, multiline_commands=['orate'], shortcuts=shortcuts)
@@ -41,7 +41,7 @@ def __init__(self, ip_addr=None, port=None, transcript_files=None):
4141
speak_parser.add_argument('words', nargs='+', help='words to say')
4242

4343
@cmd2.with_argparser(speak_parser)
44-
def do_speak(self, args: argparse.Namespace):
44+
def do_speak(self, args: argparse.Namespace) -> None:
4545
"""Repeats what you tell me to."""
4646
words = []
4747
for word in args.words:
@@ -62,7 +62,7 @@ def do_speak(self, args: argparse.Namespace):
6262
tag_parser.add_argument('content', nargs='+', help='content to surround with tag')
6363

6464
@cmd2.with_argparser(tag_parser)
65-
def do_tag(self, args: argparse.Namespace):
65+
def do_tag(self, args: argparse.Namespace) -> None:
6666
"""create an html tag"""
6767
# The Namespace always includes the Statement object created when parsing the command line
6868
statement = args.cmd2_statement.get()
@@ -72,7 +72,7 @@ def do_tag(self, args: argparse.Namespace):
7272
self.poutput('<{0}>{1}</{0}>'.format(args.tag, ' '.join(args.content)))
7373

7474
@cmd2.with_argument_list
75-
def do_tagg(self, arglist: list[str]):
75+
def do_tagg(self, arglist: list[str]) -> None:
7676
"""version of creating an html tag using arglist instead of argparser"""
7777
if len(arglist) >= 2:
7878
tag = arglist[0]

examples/default_categories.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class ChildInheritsParentCategories(MyBaseCommandSet):
2020
This subclass doesn't declare any categories so all commands here are also categorized under 'Default Category'
2121
"""
2222

23-
def do_hello(self, _: cmd2.Statement):
23+
def do_hello(self, _: cmd2.Statement) -> None:
2424
self._cmd.poutput('Hello')
2525

26-
def do_world(self, _: cmd2.Statement):
26+
def do_world(self, _: cmd2.Statement) -> None:
2727
self._cmd.poutput('World')
2828

2929

@@ -34,7 +34,7 @@ class ChildOverridesParentCategoriesNonHeritable(MyBaseCommandSet):
3434
CommandSet will not inherit this category and will, instead, inherit 'Default Category'
3535
"""
3636

37-
def do_goodbye(self, _: cmd2.Statement):
37+
def do_goodbye(self, _: cmd2.Statement) -> None:
3838
self._cmd.poutput('Goodbye')
3939

4040

@@ -44,7 +44,7 @@ class GrandchildInheritsGrandparentCategory(ChildOverridesParentCategoriesNonHer
4444
by the grandparent class.
4545
"""
4646

47-
def do_aloha(self, _: cmd2.Statement):
47+
def do_aloha(self, _: cmd2.Statement) -> None:
4848
self._cmd.poutput('Aloha')
4949

5050

@@ -55,7 +55,7 @@ class ChildOverridesParentCategories(MyBaseCommandSet):
5555
category declaration.
5656
"""
5757

58-
def do_bonjour(self, _: cmd2.Statement):
58+
def do_bonjour(self, _: cmd2.Statement) -> None:
5959
self._cmd.poutput('Bonjour')
6060

6161

@@ -65,7 +65,7 @@ class GrandchildInheritsHeritable(ChildOverridesParentCategories):
6565
CommandSet will be categorized under 'Heritable Category'
6666
"""
6767

68-
def do_monde(self, _: cmd2.Statement):
68+
def do_monde(self, _: cmd2.Statement) -> None:
6969
self._cmd.poutput('Monde')
7070

7171

@@ -74,10 +74,10 @@ class ExampleApp(cmd2.Cmd):
7474
Example to demonstrate heritable default categories
7575
"""
7676

77-
def __init__(self):
77+
def __init__(self) -> None:
7878
super().__init__()
7979

80-
def do_something(self, arg):
80+
def do_something(self, arg) -> None:
8181
self.poutput('this is the something command')
8282

8383

examples/dynamic_commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class CommandsInLoop(cmd2.Cmd):
1717
"""Example of dynamically adding do_* commands."""
1818

19-
def __init__(self):
19+
def __init__(self) -> None:
2020
# Add dynamic commands before calling cmd2.Cmd's init since it validates command names
2121
for command in COMMAND_LIST:
2222
# Create command function and add help category to it
@@ -34,11 +34,11 @@ def __init__(self):
3434

3535
super().__init__(include_ipy=True)
3636

37-
def send_text(self, args: cmd2.Statement, *, text: str):
37+
def send_text(self, args: cmd2.Statement, *, text: str) -> None:
3838
"""Simulate sending text to a server and printing the response."""
3939
self.poutput(text.capitalize())
4040

41-
def text_help(self, *, text: str):
41+
def text_help(self, *, text: str) -> None:
4242
"""Deal with printing help for the dynamically added commands."""
4343
self.poutput(f"Simulate sending {text!r} to a server and printing the response")
4444

examples/environment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class EnvironmentApp(cmd2.Cmd):
1010
"""Example cmd2 application."""
1111

12-
def __init__(self):
12+
def __init__(self) -> None:
1313
super().__init__()
1414
self.degrees_c = 22
1515
self.sunny = False
@@ -18,7 +18,7 @@ def __init__(self):
1818
)
1919
self.add_settable(cmd2.Settable('sunny', bool, 'Is it sunny outside?', self))
2020

21-
def do_sunbathe(self, arg):
21+
def do_sunbathe(self, arg) -> None:
2222
"""Attempt to sunbathe."""
2323
if self.degrees_c < 20:
2424
result = f"It's {self.degrees_c} C - are you a penguin?"
@@ -28,7 +28,7 @@ def do_sunbathe(self, arg):
2828
result = 'UV is bad for your skin.'
2929
self.poutput(result)
3030

31-
def _onchange_degrees_c(self, param_name, old, new):
31+
def _onchange_degrees_c(self, param_name, old, new) -> None:
3232
# if it's over 40C, it's gotta be sunny, right?
3333
if new > 40:
3434
self.sunny = True

examples/event_loops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Cmd2EventBased(cmd2.Cmd):
1313
"""Basic example of how to run cmd2 without it controlling the main loop."""
1414

15-
def __init__(self):
15+
def __init__(self) -> None:
1616
super().__init__()
1717

1818
# ... your class code here ...

examples/example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CmdLineApp(cmd2.Cmd):
2424
MUMBLE_FIRST = ['so', 'like', 'well']
2525
MUMBLE_LAST = ['right?']
2626

27-
def __init__(self):
27+
def __init__(self) -> None:
2828
shortcuts = cmd2.DEFAULT_SHORTCUTS
2929
shortcuts.update({'&': 'speak'})
3030
super().__init__(multiline_commands=['orate'], shortcuts=shortcuts)
@@ -40,7 +40,7 @@ def __init__(self):
4040
speak_parser.add_argument('words', nargs='+', help='words to say')
4141

4242
@cmd2.with_argparser(speak_parser)
43-
def do_speak(self, args):
43+
def do_speak(self, args) -> None:
4444
"""Repeats what you tell me to."""
4545
words = []
4646
for word in args.words:
@@ -62,7 +62,7 @@ def do_speak(self, args):
6262
mumble_parser.add_argument('words', nargs='+', help='words to say')
6363

6464
@cmd2.with_argparser(mumble_parser)
65-
def do_mumble(self, args):
65+
def do_mumble(self, args) -> None:
6666
"""Mumbles what you tell me to."""
6767
repetitions = args.repeat or 1
6868
for _ in range(min(repetitions, self.maxrepeats)):

0 commit comments

Comments
 (0)