Skip to content

Commit 0c35da8

Browse files
committed
Enabled ruff PERF ruleset for performance checking
Also: - Converted a couple loops to list or dictionary comprehensions for performance - Added a "make typecheck" command for running mypy by itself
1 parent 5490ed6 commit 0c35da8

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ format: ## Perform ruff formatting
2121
lint: ## Perform ruff linting
2222
@uv run ruff check --fix
2323

24+
.PHONY: typecheck
25+
typecheck: ## Perform type checking
26+
@uv run mypy
27+
2428
.PHONY: test
2529
test: ## Test the code with pytest.
2630
@echo "🚀 Testing code: Running pytest"

cmd2/argparse_custom.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,7 @@ def _add_argument_wrapper(
812812
kwargs['nargs'] = nargs_adjusted
813813

814814
# Extract registered custom keyword arguments
815-
custom_attribs: dict[str, Any] = {}
816-
for keyword, value in kwargs.items():
817-
if keyword in CUSTOM_ACTION_ATTRIBS:
818-
custom_attribs[keyword] = value
815+
custom_attribs = {keyword: value for keyword, value in kwargs.items() if keyword in CUSTOM_ACTION_ATTRIBS}
819816
for keyword in custom_attribs:
820817
del kwargs[keyword]
821818

cmd2/parsing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ def argv(self) -> list[str]:
214214
"""
215215
if self.command:
216216
rtn = [utils.strip_quotes(self.command)]
217-
for cur_token in self.arg_list:
218-
rtn.append(utils.strip_quotes(cur_token))
217+
rtn.extend(utils.strip_quotes(cur_token) for cur_token in self.arg_list)
219218
else:
220219
rtn = []
221220

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ select = [
190190
"ISC", # flake8-implicit-str-concat (warnings related to implicit vs explicit string concatenation)
191191
"LOG", # flake8-logging (warn about potential logger issues, but very pedantic)
192192
# "N", # pep8-naming (force idiomatic naming for classes, functions/methods, and variables/arguments)
193-
"NPY", # NumPy specific rules
194-
"PD", # pandas-vet (Pandas specific rules)
195-
# "PERF", # Perflint (warn about performance issues)
193+
"NPY", # NumPy specific rules
194+
"PD", # pandas-vet (Pandas specific rules)
195+
"PERF", # Perflint (warn about performance issues)
196196
# "PGH", # pygrep-hooks (force specific rule codes when ignoring type or linter issues on a line)
197197
# "PIE", # flake8-pie (eliminate unnecessary use of pass, range starting at 0, etc.)
198198
"PLC", # Pylint Conventions

0 commit comments

Comments
 (0)