Skip to content

Commit bbba040

Browse files
committed
Enabled ruff PLW ruleset for PyLint warnings
1 parent 47a52ad commit bbba040

File tree

9 files changed

+25
-18
lines changed

9 files changed

+25
-18
lines changed

cmd2/argparse_completer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,5 +775,5 @@ def set_default_ap_completer_type(completer_type: Type[ArgparseCompleter]) -> No
775775
776776
:param completer_type: Type that is a subclass of ArgparseCompleter.
777777
"""
778-
global DEFAULT_AP_COMPLETER
778+
global DEFAULT_AP_COMPLETER # noqa: PLW0603
779779
DEFAULT_AP_COMPLETER = completer_type

cmd2/argparse_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,5 +1407,5 @@ def set_default_argument_parser_type(parser_type: type[argparse.ArgumentParser])
14071407
Set the default ArgumentParser class for a cmd2 app. This must be called prior to loading cmd2.py if
14081408
you want to override the parser for cmd2's built-in commands. See examples/override_parser.py.
14091409
"""
1410-
global DEFAULT_ARGUMENT_PARSER
1410+
global DEFAULT_ARGUMENT_PARSER # noqa: PLW0603
14111411
DEFAULT_ARGUMENT_PARSER = parser_type

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,7 +2653,7 @@ def runcmds_plus_hooks(
26532653
"""
26542654
for line in cmds:
26552655
if isinstance(line, HistoryItem):
2656-
line = line.raw
2656+
line = line.raw # noqa: PLW2901
26572657

26582658
if self.echo:
26592659
self.poutput(f'{self.prompt}{line}')
@@ -4974,7 +4974,7 @@ def _generate_transcript(
49744974
first = True
49754975
command = ''
49764976
if isinstance(history_item, HistoryItem):
4977-
history_item = history_item.raw
4977+
history_item = history_item.raw # noqa: PLW2901
49784978
for line in history_item.splitlines():
49794979
if first:
49804980
command += f"{self.prompt}{line}\n"

cmd2/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _parse_positionals(args: tuple[Any, ...]) -> tuple['cmd2.Cmd', Union[Stateme
8787

8888
if isinstance(arg, (Cmd, CommandSet)) and len(args) > pos + 1:
8989
if isinstance(arg, CommandSet):
90-
arg = arg._cmd
90+
arg = arg._cmd # noqa: PLW2901
9191
next_arg = args[pos + 1]
9292
if isinstance(next_arg, (Statement, str)):
9393
return arg, args[pos + 1]

cmd2/parsing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,12 @@ def _expand(self, line: str) -> str:
660660
if line.startswith(shortcut):
661661
# If the next character after the shortcut isn't a space, then insert one
662662
shortcut_len = len(shortcut)
663+
effective_expansion = expansion
663664
if len(line) == shortcut_len or line[shortcut_len] != ' ':
664-
expansion += ' '
665+
effective_expansion += ' '
665666

666667
# Expand the shortcut
667-
line = line.replace(shortcut, expansion, 1)
668+
line = line.replace(shortcut, effective_expansion, 1)
668669
break
669670
return line
670671

cmd2/table_creator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,6 @@ def generate_row_bottom_border(self) -> str:
894894
if self.column_borders:
895895
inter_cell += '┼'
896896
inter_cell += self.padding * '─'
897-
inter_cell = inter_cell
898897

899898
post_line = self.padding * '─' + '╢'
900899

cmd2/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,14 @@ def find_editor() -> Optional[str]:
376376
else:
377377
paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
378378

379-
for editor, path in itertools.product(editors, paths):
380-
editor_path = os.path.join(path, editor)
379+
for possible_editor, path in itertools.product(editors, paths):
380+
editor_path = os.path.join(path, possible_editor)
381381
if os.path.isfile(editor_path) and os.access(editor_path, os.X_OK):
382382
if sys.platform[:3] == 'win':
383383
# Remove extension from Windows file names
384-
editor = os.path.splitext(editor)[0]
384+
editor = os.path.splitext(possible_editor)[0]
385+
else:
386+
editor = possible_editor
385387
break
386388
else:
387389
editor = None
@@ -902,7 +904,7 @@ def align_text(
902904
text_buf.write('\n')
903905

904906
if truncate:
905-
line = truncate_line(line, width)
907+
line = truncate_line(line, width) # noqa: PLW2901
906908

907909
line_width = ansi.style_aware_wcswidth(line)
908910
if line_width == -1:

examples/async_printing.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ def _get_alerts(self) -> list[str]:
9090
Reports alerts
9191
:return: the list of alerts
9292
"""
93-
global ALERTS
94-
9593
cur_time = time.monotonic()
9694
if cur_time < self._next_alert_time:
9795
return []
@@ -121,8 +119,6 @@ def _generate_alert_str(self) -> str:
121119
Combines alerts into one string that can be printed to the terminal
122120
:return: the alert string
123121
"""
124-
global ALERTS
125-
126122
alert_str = ''
127123
alerts = self._get_alerts()
128124

pyproject.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ select = [
198198
"PLC", # Pylint Conventions
199199
"PLE", # Pylint Errors
200200
# "PLR", # Pylint Refactoring suggestions
201-
# "PLW", # Pylint Warnings
201+
"PLW", # Pylint Warnings
202202
# "PT", # flake8-pytest-style (warnings about unit test best practices)
203203
# "PTH", # flake8-use-pathlib (force use of pathlib instead of os.path)
204204
"PYI", # flake8-pyi (warnings related to type hint best practices)
@@ -255,7 +255,8 @@ per-file-ignores."cmd2/__init__.py" = [
255255
]
256256

257257
per-file-ignores."examples/*.py" = [
258-
"INP001", # Module is part of an implicit namespace
258+
"INP001", # Module is part of an implicit namespace
259+
"PLW2901", # loop variable overwritten inside loop
259260
]
260261

261262
per-file-ignores."examples/override_parser.py" = [
@@ -278,11 +279,19 @@ per-file-ignores."tests/*.py" = [
278279
"E501", # Line too long
279280
]
280281

282+
per-file-ignores."tests/test_argparse.py" = [
283+
"PLW2901", # loop variable overwritten inside loop
284+
]
285+
281286
per-file-ignores."tests/pyscript/*.py" = [
282287
"F821", # Undefined name `app`
283288
"INP001", # Module is part of an implicit namespace
284289
]
285290

291+
per-file-ignores."tests_isolated/test_commandset/test_commandset.py" = [
292+
"PLW0603", # Using the global statement to update {name} is discouraged
293+
]
294+
286295

287296
[tool.ruff.format]
288297
# Like Black, use double quotes for strings.

0 commit comments

Comments
 (0)