Skip to content

Commit 336502a

Browse files
committed
Enabled ruff C4 ruleset and applied fixes
1 parent 0c35da8 commit 336502a

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

cmd2/argparse_custom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,15 +1031,15 @@ def _format_usage(
10311031

10321032
# if usage is specified, use that
10331033
if usage is not None:
1034-
usage %= dict(prog=self._prog)
1034+
usage %= {"prog": self._prog}
10351035

10361036
# if no optionals or positionals are available, usage is just prog
10371037
elif not actions:
1038-
usage = '%(prog)s' % dict(prog=self._prog)
1038+
usage = '%(prog)s' % {"prog": self._prog}
10391039

10401040
# if optionals and positionals are available, calculate usage
10411041
else:
1042-
prog = '%(prog)s' % dict(prog=self._prog)
1042+
prog = '%(prog)s' % {"prog": self._prog}
10431043

10441044
# split optionals from positionals
10451045
optionals = []

cmd2/cmd2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def __init__(
411411
self.max_completion_items = 50
412412

413413
# A dictionary mapping settable names to their Settable instance
414-
self._settables: dict[str, Settable] = dict()
414+
self._settables: dict[str, Settable] = {}
415415
self._always_prefix_settables: bool = False
416416

417417
# CommandSet containers
@@ -438,7 +438,7 @@ def __init__(
438438
self.exclude_from_history = ['eof', 'history']
439439

440440
# Dictionary of macro names and their values
441-
self.macros: dict[str, Macro] = dict()
441+
self.macros: dict[str, Macro] = {}
442442

443443
# Keeps track of typed command history in the Python shell
444444
self._py_history: list[str] = []
@@ -447,7 +447,7 @@ def __init__(
447447
self.py_bridge_name = 'app'
448448

449449
# Defines app-specific variables/functions available in Python shells and pyscripts
450-
self.py_locals: dict[str, Any] = dict()
450+
self.py_locals: dict[str, Any] = {}
451451

452452
# True if running inside a Python shell or pyscript, False otherwise
453453
self._in_py = False
@@ -546,7 +546,7 @@ def __init__(
546546
# Commands that have been disabled from use. This is to support commands that are only available
547547
# during specific states of the application. This dictionary's keys are the command names and its
548548
# values are DisabledCommand objects.
549-
self.disabled_commands: dict[str, DisabledCommand] = dict()
549+
self.disabled_commands: dict[str, DisabledCommand] = {}
550550

551551
# If any command has been categorized, then all other commands that haven't been categorized
552552
# will display under this section in the help output.
@@ -2889,7 +2889,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
28892889
# Create pipe process in a separate group to isolate our signals from it. If a Ctrl-C event occurs,
28902890
# our sigint handler will forward it only to the most recent pipe process. This makes sure pipe
28912891
# processes close in the right order (most recent first).
2892-
kwargs: dict[str, Any] = dict()
2892+
kwargs: dict[str, Any] = {}
28932893
if sys.platform == 'win32':
28942894
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
28952895
else:
@@ -4238,7 +4238,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
42384238
import signal
42394239
import subprocess
42404240

4241-
kwargs: dict[str, Any] = dict()
4241+
kwargs: dict[str, Any] = {}
42424242

42434243
# Set OS-specific parameters
42444244
if sys.platform.startswith('win'):

cmd2/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def arg_decorator(func: ArgparseCommandFunc[CommandParent]) -> ArgparseCommandFu
437437
setattr(func, constants.SUBCMD_ATTR_NAME, subcommand)
438438

439439
# Keyword arguments for subparsers.add_parser()
440-
add_parser_kwargs: dict[str, Any] = dict()
440+
add_parser_kwargs: dict[str, Any] = {}
441441
if help is not None:
442442
add_parser_kwargs['help'] = help
443443
if aliases:

cmd2/table_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def __init__(self) -> None:
476476
total_lines = 0
477477

478478
# Generate the cells for this row
479-
cells = list()
479+
cells = []
480480

481481
for col_index, col in enumerate(self.cols):
482482
cell = Cell()

cmd2/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ class StyleState:
757757

758758
def __init__(self) -> None:
759759
# Contains styles still in effect, keyed by their index in styles_to_parse
760-
self.style_dict: dict[int, str] = dict()
760+
self.style_dict: dict[int, str] = {}
761761

762762
# Indexes into style_dict
763763
self.reset_all: Optional[int] = None

examples/table_creation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def basic_tables():
7474
"""Demonstrates basic examples of the table classes"""
7575

7676
# Table data which demonstrates handling of wrapping and text styles
77-
data_list: list[list[Any]] = list()
77+
data_list: list[list[Any]] = []
7878
data_list.append(["Billy Smith", "123 Sesame St.\nFake Town, USA 33445", DollarFormatter(100333.03)])
7979
data_list.append(
8080
[
@@ -94,7 +94,7 @@ def basic_tables():
9494
data_list.append(["John Jones", "9235 Highway 32\n" + green("Greenville") + ", SC 29604", DollarFormatter(82987.71)])
9595

9696
# Table Columns (width does not account for any borders or padding which may be added)
97-
columns: list[Column] = list()
97+
columns: list[Column] = []
9898
columns.append(Column("Name", width=20))
9999
columns.append(Column("Address", width=38))
100100
columns.append(
@@ -157,7 +157,7 @@ def nested_tables():
157157

158158
# Define table which presents Author data fields vertically with no header.
159159
# This will be nested in the parent table's first column.
160-
author_columns: list[Column] = list()
160+
author_columns: list[Column] = []
161161
author_columns.append(Column("", width=14))
162162
author_columns.append(Column("", width=20))
163163

@@ -172,7 +172,7 @@ def nested_tables():
172172

173173
# Define AlternatingTable for books checked out by people in the first table.
174174
# This will be nested in the parent table's second column.
175-
books_columns: list[Column] = list()
175+
books_columns: list[Column] = []
176176
books_columns.append(Column(ansi.style("Title", bold=True), width=25))
177177
books_columns.append(
178178
Column(
@@ -194,7 +194,7 @@ def nested_tables():
194194

195195
# Define BorderedTable for relatives of the author
196196
# This will be nested in the parent table's third column.
197-
relative_columns: list[Column] = list()
197+
relative_columns: list[Column] = []
198198
relative_columns.append(Column(ansi.style("Name", bold=True), width=25))
199199
relative_columns.append(Column(ansi.style("Relationship", bold=True), width=12))
200200

@@ -218,7 +218,7 @@ def nested_tables():
218218
)
219219

220220
# Define parent AlternatingTable which contains Author and Book tables
221-
parent_tbl_columns: list[Column] = list()
221+
parent_tbl_columns: list[Column] = []
222222

223223
# All of the nested tables already have background colors. Set style_data_text
224224
# to False so the parent AlternatingTable does not apply background color to them.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ select = [
163163
"ASYNC", # flake8-async (async await bugs)
164164
# "B", # flake8-bugbear (various likely bugs and design issues)
165165
# "BLE", # flake8-blind-except (force more specific exception types than just Exception)
166-
# "C4", # flake8-comprehensions (warn about things that could be written as a comprehensions but aren't)
166+
"C4", # flake8-comprehensions (warn about things that could be written as a comprehensions but aren't)
167167
"C90", # McCabe cyclomatic complexity (warn about functions that are too complex)
168168
# "COM", # flake8-commas (forces commas at the end of every type of iterable/container
169169
# "CPY", # flake8-copyright (warn about missing copyright notice at top of file - currently in preview)

0 commit comments

Comments
 (0)