Skip to content

Commit cdc9c35

Browse files
committed
Finish enabling ruff B rulset for flake8-bugbear
Disabled B010 rule for not calling setattr with constant attribute value in cmd2/argparse_custom.py file due to type checking going nuts if we tried to apply it.
1 parent bf45ff7 commit cdc9c35

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

cmd2/argparse_custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def __call__(self) -> list[str]: ... # pragma: no cover
319319
class ChoicesProviderFuncWithTokens(Protocol):
320320
"""Function that returns a list of choices in support of tab completion and accepts a dictionary of prior arguments."""
321321

322-
def __call__(self, *, arg_tokens: dict[str, list[str]] = {}) -> list[str]: ... # pragma: no cover
322+
def __call__(self, *, arg_tokens: dict[str, list[str]]) -> list[str]: ... # pragma: no cover
323323

324324

325325
ChoicesProviderFunc = Union[ChoicesProviderFuncBase, ChoicesProviderFuncWithTokens]
@@ -351,7 +351,7 @@ def __call__(
351351
begidx: int,
352352
endidx: int,
353353
*,
354-
arg_tokens: dict[str, list[str]] = {},
354+
arg_tokens: dict[str, list[str]] = {}, # noqa: B006
355355
) -> list[str]: ... # pragma: no cover
356356

357357

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ def __init__(
377377
"""
378378
# Check if py or ipy need to be disabled in this instance
379379
if not include_py:
380-
setattr(self, 'do_py', None)
380+
setattr(self, 'do_py', None) # noqa: B010
381381
if not include_ipy:
382-
setattr(self, 'do_ipy', None)
382+
setattr(self, 'do_ipy', None) # noqa: B010
383383

384384
# initialize plugin system
385385
# needs to be done before we call __init__(0)

pyproject.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ select = [
161161
"ANN", # flake8-annotations (missing type annotations for arguments or return types)
162162
"ARG", # flake8-unused-arguments (functions or methods with arguments that are never used)
163163
"ASYNC", # flake8-async (async await bugs)
164-
# "B", # flake8-bugbear (various likely bugs and design issues)
165-
"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)
167-
"C90", # McCabe cyclomatic complexity (warn about functions that are too complex)
168-
"COM", # flake8-commas (forces commas at the end of every type of iterable/container
164+
"B", # flake8-bugbear (various likely bugs and design issues)
165+
"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)
167+
"C90", # McCabe cyclomatic complexity (warn about functions that are too complex)
168+
"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)
170170
# "D", # pydocstyle (warn about things like missing docstrings)
171171
# "DOC", # pydoclint (docstring warnings - currently in preview)
@@ -258,6 +258,11 @@ per-file-ignores."cmd2/__init__.py" = [
258258
"F401", # Unused import
259259
]
260260

261+
per-file-ignores."cmd2/argparse_custom.py" = [
262+
"B010", # Do not call setattr with a constant attribute value
263+
]
264+
265+
261266
per-file-ignores."examples/*.py" = [
262267
"ANN", # Ignore all type annotation rules in examples folder
263268
"D", # Ignore all pydocstyle rules in examples folder

0 commit comments

Comments
 (0)