Skip to content

Commit 884758d

Browse files
committed
Cleaned up remaining import of Dict and List from Typing
1 parent 74b21c8 commit 884758d

File tree

15 files changed

+38
-72
lines changed

15 files changed

+38
-72
lines changed

cmd2/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER.
1313
# Do this before loading cmd2.Cmd class so its commands use the custom parser.
1414
import argparse
15-
from typing import List
1615

1716
from .ansi import (
1817
Bg,
@@ -56,7 +55,7 @@
5655
from .py_bridge import CommandResult
5756
from .utils import CompletionMode, CustomCompletionSettings, Settable, categorize
5857

59-
__all__: List[str] = [
58+
__all__: list[str] = [
6059
'COMMAND_NAME',
6160
'DEFAULT_SHORTCUTS',
6261
# ANSI Exports

cmd2/ansi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,10 @@ def style(
986986
:raises TypeError: if bg isn't None or a subclass of BgColor
987987
:return: the stylized string
988988
"""
989-
# List of strings that add style
989+
# list of strings that add style
990990
additions: list[AnsiSequence] = []
991991

992-
# List of strings that remove style
992+
# list of strings that remove style
993993
removals: list[AnsiSequence] = []
994994

995995
# Process the style settings

cmd2/exceptions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Custom exceptions for cmd2"""
22

3-
from typing import (
4-
Any,
5-
)
3+
from typing import Any
64

75
############################################################################################################
86
# The following exceptions are part of the public API

cmd2/plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from dataclasses import (
44
dataclass,
55
)
6-
from typing import (
7-
Optional,
8-
)
6+
from typing import Optional
97

108
from .parsing import (
119
Statement,

cmd2/rl_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
from enum import (
77
Enum,
88
)
9-
from typing import (
10-
Union,
11-
)
9+
from typing import Union
1210

1311
#########################################################################################################################
1412
# NOTE ON LIBEDIT:

examples/modular_commands/commandset_complex.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
"""
44

55
import argparse
6-
from typing import (
7-
List,
8-
)
96

107
import cmd2
118

@@ -23,7 +20,7 @@ def do_banana(self, statement: cmd2.Statement):
2320
cranberry_parser.add_argument('arg1', choices=['lemonade', 'juice', 'sauce'])
2421

2522
@cmd2.with_argparser(cranberry_parser, with_unknown_args=True)
26-
def do_cranberry(self, ns: argparse.Namespace, unknown: List[str]):
23+
def do_cranberry(self, ns: argparse.Namespace, unknown: list[str]):
2724
self._cmd.poutput('Cranberry {}!!'.format(ns.arg1))
2825
if unknown and len(unknown):
2926
self._cmd.poutput('Unknown: ' + ', '.join(['{}'] * len(unknown)).format(*unknown))
@@ -34,12 +31,12 @@ def help_cranberry(self):
3431

3532
@cmd2.with_argument_list
3633
@cmd2.with_category('Also Alone')
37-
def do_durian(self, args: List[str]):
34+
def do_durian(self, args: list[str]):
3835
"""Durian Command"""
3936
self._cmd.poutput('{} Arguments: '.format(len(args)))
4037
self._cmd.poutput(', '.join(['{}'] * len(args)).format(*args))
4138

42-
def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
39+
def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
4340
return self._cmd.basic_complete(text, line, begidx, endidx, ['stinks', 'smells', 'disgusting'])
4441

4542
elderberry_parser = cmd2.Cmd2ArgumentParser()

examples/modular_commands_main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
import argparse
88
from collections.abc import Iterable
9-
from typing import (
10-
Optional,
11-
)
9+
from typing import Optional
1210

1311
from modular_commands.commandset_basic import ( # noqa: F401
1412
BasicCompletionCommandSet,

examples/scripts/save_help_text.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import argparse
77
import os
88
import sys
9-
from typing import (
10-
List,
11-
TextIO,
12-
)
9+
from typing import TextIO
1310

1411
ASTERISKS = "********************************************************"
1512

1613

17-
def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
14+
def get_sub_commands(parser: argparse.ArgumentParser) -> list[str]:
1815
"""Get a list of subcommands for an ArgumentParser"""
1916
sub_cmds = []
2017

examples/table_creation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
import functools
55
import sys
6-
from typing import (
7-
Any,
8-
)
6+
from typing import Any
97

108
from cmd2 import (
119
EightBitBg,

plugins/template/cmd2_myplugin/myplugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
import functools
55
from collections.abc import Callable
6-
from typing import (
7-
TYPE_CHECKING,
8-
)
6+
from typing import TYPE_CHECKING
97

108
import cmd2
119

tests/test_argparse.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44

55
import argparse
6-
from typing import (
7-
Optional,
8-
)
6+
from typing import Optional
97

108
import pytest
119

tests/test_argparse_completer.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
import argparse
66
import numbers
7-
from typing import (
8-
Dict,
9-
List,
10-
cast,
11-
)
7+
from typing import cast
128

139
import pytest
1410

@@ -37,11 +33,11 @@
3733
standalone_completions = ['standalone', 'completer']
3834

3935

40-
def standalone_choice_provider(cli: cmd2.Cmd) -> List[str]:
36+
def standalone_choice_provider(cli: cmd2.Cmd) -> list[str]:
4137
return standalone_choices
4238

4339

44-
def standalone_completer(cli: cmd2.Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]:
40+
def standalone_completer(cli: cmd2.Cmd, text: str, line: str, begidx: int, endidx: int) -> list[str]:
4541
return cli.basic_complete(text, line, begidx, endidx, standalone_completions)
4642

4743

@@ -113,7 +109,7 @@ def do_pos_and_flag(self, args: argparse.Namespace) -> None:
113109
TUPLE_METAVAR = ('arg1', 'others')
114110
CUSTOM_DESC_HEADER = "Custom Header"
115111

116-
# Lists used in our tests (there is a mix of sorted and unsorted on purpose)
112+
# lists used in our tests (there is a mix of sorted and unsorted on purpose)
117113
non_negative_num_choices = [1, 2, 3, 0.5, 22]
118114
num_choices = [-1, 1, -2, 2.5, 0, -12]
119115
static_choices_list = ['static', 'choices', 'stop', 'here']
@@ -123,11 +119,11 @@ def do_pos_and_flag(self, args: argparse.Namespace) -> None:
123119
# This tests that CompletionItems created with numerical values are sorted as numbers.
124120
num_completion_items = [CompletionItem(5, "Five"), CompletionItem(1.5, "One.Five"), CompletionItem(2, "Five")]
125121

126-
def choices_provider(self) -> List[str]:
122+
def choices_provider(self) -> list[str]:
127123
"""Method that provides choices"""
128124
return self.choices_from_provider
129125

130-
def completion_item_method(self) -> List[CompletionItem]:
126+
def completion_item_method(self) -> list[CompletionItem]:
131127
"""Choices method that returns CompletionItems"""
132128
items = []
133129
for i in range(10):
@@ -189,13 +185,13 @@ def do_choices(self, args: argparse.Namespace) -> None:
189185
completions_for_pos_1 = ['completions', 'positional_1', 'probably', 'missed', 'spot']
190186
completions_for_pos_2 = ['completions', 'positional_2', 'probably', 'missed', 'me']
191187

192-
def flag_completer(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
188+
def flag_completer(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
193189
return self.basic_complete(text, line, begidx, endidx, self.completions_for_flag)
194190

195-
def pos_1_completer(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
191+
def pos_1_completer(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
196192
return self.basic_complete(text, line, begidx, endidx, self.completions_for_pos_1)
197193

198-
def pos_2_completer(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
194+
def pos_2_completer(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
199195
return self.basic_complete(text, line, begidx, endidx, self.completions_for_pos_2)
200196

201197
completer_parser = Cmd2ArgumentParser()
@@ -263,11 +259,11 @@ def do_hint(self, args: argparse.Namespace) -> None:
263259
############################################################################################################
264260
# Begin code related to CompletionError
265261
############################################################################################################
266-
def completer_raise_error(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
262+
def completer_raise_error(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
267263
"""Raises CompletionError"""
268264
raise CompletionError('completer broke something')
269265

270-
def choice_raise_error(self) -> List[str]:
266+
def choice_raise_error(self) -> list[str]:
271267
"""Raises CompletionError"""
272268
raise CompletionError('choice broke something')
273269

@@ -282,13 +278,13 @@ def do_raise_completion_error(self, args: argparse.Namespace) -> None:
282278
############################################################################################################
283279
# Begin code related to receiving arg_tokens
284280
############################################################################################################
285-
def choices_takes_arg_tokens(self, arg_tokens: Dict[str, List[str]]) -> List[str]:
281+
def choices_takes_arg_tokens(self, arg_tokens: dict[str, list[str]]) -> list[str]:
286282
"""Choices function that receives arg_tokens from ArgparseCompleter"""
287283
return [arg_tokens['parent_arg'][0], arg_tokens['subcommand'][0]]
288284

289285
def completer_takes_arg_tokens(
290-
self, text: str, line: str, begidx: int, endidx: int, arg_tokens: Dict[str, List[str]]
291-
) -> List[str]:
286+
self, text: str, line: str, begidx: int, endidx: int, arg_tokens: dict[str, list[str]]
287+
) -> list[str]:
292288
"""Completer function that receives arg_tokens from ArgparseCompleter"""
293289
match_against = [arg_tokens['parent_arg'][0], arg_tokens['subcommand'][0]]
294290
return self.basic_complete(text, line, begidx, endidx, match_against)
@@ -1204,7 +1200,7 @@ def test_complete_standalone(ac_app, flag, completions):
12041200

12051201
# Custom ArgparseCompleter-based class
12061202
class CustomCompleter(argparse_completer.ArgparseCompleter):
1207-
def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, matched_flags: List[str]) -> List[str]:
1203+
def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, matched_flags: list[str]) -> list[str]:
12081204
"""Override so flags with 'complete_when_ready' set to True will complete only when app is ready"""
12091205

12101206
# Find flags which should not be completed and place them in matched_flags

tests/test_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,6 @@ def test_context_flag_exit_err(context_flag):
334334

335335

336336
def test_remove_overridden_styles():
337-
from typing import (
338-
List,
339-
)
340-
341337
from cmd2 import (
342338
Bg,
343339
EightBitBg,
@@ -348,7 +344,7 @@ def test_remove_overridden_styles():
348344
TextStyle,
349345
)
350346

351-
def make_strs(styles_list: List[ansi.AnsiSequence]) -> List[str]:
347+
def make_strs(styles_list: list[ansi.AnsiSequence]) -> list[str]:
352348
return [str(s) for s in styles_list]
353349

354350
# Test Reset All

tests_isolated/test_commandset/test_categories.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
Simple example demonstrating basic CommandSet usage.
33
"""
44

5-
from typing import (
6-
Any,
7-
)
5+
from typing import Any
86

97
import cmd2
108
from cmd2 import (

tests_isolated/test_commandset/test_commandset.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
import argparse
66
import signal
7-
from typing import (
8-
List,
9-
)
107

118
import pytest
129

@@ -59,7 +56,7 @@ def do_banana(self, statement: cmd2.Statement):
5956
cranberry_parser.add_argument('arg1', choices=['lemonade', 'juice', 'sauce'])
6057

6158
@cmd2.with_argparser(cranberry_parser, with_unknown_args=True)
62-
def do_cranberry(self, ns: argparse.Namespace, unknown: List[str]):
59+
def do_cranberry(self, ns: argparse.Namespace, unknown: list[str]):
6360
self._cmd.poutput('Cranberry {}!!'.format(ns.arg1))
6461
if unknown and len(unknown):
6562
self._cmd.poutput('Unknown: ' + ', '.join(['{}'] * len(unknown)).format(*unknown))
@@ -70,13 +67,13 @@ def help_cranberry(self):
7067

7168
@cmd2.with_argument_list
7269
@cmd2.with_category('Also Alone')
73-
def do_durian(self, args: List[str]):
70+
def do_durian(self, args: list[str]):
7471
"""Durian Command"""
7572
self._cmd.poutput('{} Arguments: '.format(len(args)))
7673
self._cmd.poutput(', '.join(['{}'] * len(args)).format(*args))
7774
self._cmd.last_result = {'args': args}
7875

79-
def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
76+
def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
8077
return self._cmd.basic_complete(text, line, begidx, endidx, ['stinks', 'smells', 'disgusting'])
8178

8279
elderberry_parser = cmd2.Cmd2ArgumentParser()
@@ -502,7 +499,7 @@ def __init__(self, dummy):
502499
def do_arugula(self, _: cmd2.Statement):
503500
self._cmd.poutput('Arugula')
504501

505-
def complete_style_arg(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
502+
def complete_style_arg(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
506503
return ['quartered', 'diced']
507504

508505
bokchoy_parser = cmd2.Cmd2ArgumentParser()
@@ -740,7 +737,7 @@ def cut_banana(self, ns: argparse.Namespace):
740737
"""Cut banana"""
741738
self.poutput('cutting banana: ' + ns.direction)
742739

743-
def complete_style_arg(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
740+
def complete_style_arg(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
744741
return ['quartered', 'diced']
745742

746743
bokchoy_parser = cmd2.Cmd2ArgumentParser()
@@ -795,7 +792,7 @@ def __init__(self, dummy):
795792
"""dummy variable prevents this from being autoloaded in other tests"""
796793
super(SupportFuncProvider, self).__init__()
797794

798-
def complete_states(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
795+
def complete_states(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
799796
assert self is complete_states_expected_self
800797
return self._cmd.basic_complete(text, line, begidx, endidx, self.states)
801798

0 commit comments

Comments
 (0)