Skip to content

Commit 93547fe

Browse files
committed
Fix lint issues across PR files
- setup.py: rename loop variable shadowing parameter (B020) - _util.py: remove unused registry import (F401), use specific except clause (E722, B904) - test_cli_app.py: use dict literals instead of dict() (C408) - main.py: extract _try_static_group to reduce complexity (C901)
1 parent 7bb0938 commit 93547fe

4 files changed

Lines changed: 47 additions & 44 deletions

File tree

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ def _minimal_ext_cmd(cmd):
158158

159159

160160
def clean(path):
161-
for path in path.glob("**/*"):
162-
if path.is_file() and path.suffix in (".so", ".cpp", ".html"):
163-
print(f"Deleting {path.name}")
164-
path.unlink()
161+
for child in path.glob("**/*"):
162+
if child.is_file() and child.suffix in (".so", ".cpp", ".html"):
163+
print(f"Deleting {child.name}")
164+
child.unlink()
165165

166166

167167
def setup_package():

spacy/cli/_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
ENV_VARS,
2727
import_file,
2828
logger,
29-
registry,
3029
run_command,
3130
)
3231

@@ -206,8 +205,8 @@ def get_git_version(
206205
"""
207206
try:
208207
ret = run_command("git --version", capture=True)
209-
except:
210-
raise RuntimeError(error)
208+
except Exception as err:
209+
raise RuntimeError(error) from err
211210
stdout = ret.stdout.strip()
212211
if not stdout or not stdout.startswith("git version"):
213212
return 0, 0

spacy/tests/test_cli_app.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -288,30 +288,30 @@ def test_find_function_invalid():
288288
example_ents = ["O", "O", "I-ANIMAL"]
289289
example_spans = [(2, 3, "ANIMAL")]
290290

291-
TRAIN_EXAMPLE_1 = dict(
292-
words=example_words_1,
293-
lemmas=example_lemmas_1,
294-
tags=example_tags,
295-
morphs=example_morphs,
296-
deps=example_deps,
297-
heads=[1, 1, 1],
298-
pos=example_pos,
299-
ents=example_ents,
300-
spans=example_spans,
301-
cats={"CAT": 1.0, "DOG": 0.0},
302-
)
303-
TRAIN_EXAMPLE_2 = dict(
304-
words=example_words_2,
305-
lemmas=example_lemmas_2,
306-
tags=example_tags,
307-
morphs=example_morphs,
308-
deps=example_deps,
309-
heads=[1, 1, 1],
310-
pos=example_pos,
311-
ents=example_ents,
312-
spans=example_spans,
313-
cats={"CAT": 0.0, "DOG": 1.0},
314-
)
291+
TRAIN_EXAMPLE_1 = {
292+
"words": example_words_1,
293+
"lemmas": example_lemmas_1,
294+
"tags": example_tags,
295+
"morphs": example_morphs,
296+
"deps": example_deps,
297+
"heads": [1, 1, 1],
298+
"pos": example_pos,
299+
"ents": example_ents,
300+
"spans": example_spans,
301+
"cats": {"CAT": 1.0, "DOG": 0.0},
302+
}
303+
TRAIN_EXAMPLE_2 = {
304+
"words": example_words_2,
305+
"lemmas": example_lemmas_2,
306+
"tags": example_tags,
307+
"morphs": example_morphs,
308+
"deps": example_deps,
309+
"heads": [1, 1, 1],
310+
"pos": example_pos,
311+
"ents": example_ents,
312+
"spans": example_spans,
313+
"cats": {"CAT": 0.0, "DOG": 1.0},
314+
}
315315

316316

317317
@pytest.mark.slow

spacy_cli/main.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,28 @@ def _try_static(argv: Iterable[str]):
3838
template = manifest["errors"]["unknown_command"]
3939
return template.replace(UNKNOWN_COMMAND_TOKEN, first), 2
4040
if first in known_groups:
41-
if len(args) == 1 or args[1] in HELP_OPTIONS:
42-
if plugin_command_names:
43-
return None
44-
return manifest["group_help"][first], 0
45-
second = args[1]
46-
if second not in known_groups[first]:
47-
if plugin_command_names:
48-
return None
49-
template = manifest["errors"]["unknown_subcommand"][first]
50-
return template.replace(UNKNOWN_SUBCOMMAND_TOKEN, second), 2
51-
if any(arg in HELP_OPTIONS for arg in args[2:]):
52-
return manifest["command_help"][f"{first} {second}"], 0
53-
return None
41+
return _try_static_group(args, first, manifest, known_groups, plugin_command_names)
5442
if any(arg in HELP_OPTIONS for arg in args[1:]):
5543
return manifest["command_help"][first], 0
5644
return None
5745

5846

47+
def _try_static_group(args, first, manifest, known_groups, plugin_command_names):
48+
if len(args) == 1 or args[1] in HELP_OPTIONS:
49+
if plugin_command_names:
50+
return None
51+
return manifest["group_help"][first], 0
52+
second = args[1]
53+
if second not in known_groups[first]:
54+
if plugin_command_names:
55+
return None
56+
template = manifest["errors"]["unknown_subcommand"][first]
57+
return template.replace(UNKNOWN_SUBCOMMAND_TOKEN, second), 2
58+
if any(arg in HELP_OPTIONS for arg in args[2:]):
59+
return manifest["command_help"][f"{first} {second}"], 0
60+
return None
61+
62+
5963
def main(argv: Optional[Iterable[str]] = None) -> None:
6064
args = sys.argv[1:] if argv is None else list(argv)
6165
try:

0 commit comments

Comments
 (0)