From 2bc31e15c90fc6835833a123ae99af11e0e6d203 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Sat, 29 Aug 2020 13:01:10 +0200 Subject: [PATCH] Tidy up and auto-format [ci skip] --- spacy/cli/project/clone.py | 1 - spacy/gold/loggers.py | 4 ++-- spacy/pipeline/attributeruler.py | 2 ++ spacy/pipeline/entity_linker.py | 2 +- spacy/tests/pipeline/test_attributeruler.py | 18 ++++++++---------- spacy/tests/test_cli.py | 6 ++---- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/spacy/cli/project/clone.py b/spacy/cli/project/clone.py index 5317c3f78..7f9a46a46 100644 --- a/spacy/cli/project/clone.py +++ b/spacy/cli/project/clone.py @@ -2,7 +2,6 @@ from typing import Optional from pathlib import Path from wasabi import msg import subprocess -import shutil import re from ... import about diff --git a/spacy/gold/loggers.py b/spacy/gold/loggers.py index e58d4a4aa..e071e5827 100644 --- a/spacy/gold/loggers.py +++ b/spacy/gold/loggers.py @@ -9,7 +9,7 @@ from wasabi import msg @registry.loggers("spacy.ConsoleLogger.v1") def console_logger(): def setup_printer( - nlp: "Language" + nlp: "Language", ) -> Tuple[Callable[[Dict[str, Any]], None], Callable]: score_cols = list(nlp.config["training"]["score_weights"]) score_widths = [max(len(col), 6) for col in score_cols] @@ -73,7 +73,7 @@ def wandb_logger(project_name: str, remove_config_values: List[str] = []): console = console_logger() def setup_logger( - nlp: "Language" + nlp: "Language", ) -> Tuple[Callable[[Dict[str, Any]], None], Callable]: config = nlp.config.interpolate() config_dot = util.dict_to_dot(config) diff --git a/spacy/pipeline/attributeruler.py b/spacy/pipeline/attributeruler.py index 4d1816238..f20038087 100644 --- a/spacy/pipeline/attributeruler.py +++ b/spacy/pipeline/attributeruler.py @@ -242,6 +242,7 @@ class AttributeRuler(Pipe): DOCS: https://spacy.io/api/attributeruler#from_bytes """ + def load_patterns(b): self.add_patterns(srsly.msgpack_loads(b)) @@ -275,6 +276,7 @@ class AttributeRuler(Pipe): exclude (Iterable[str]): String names of serialization fields to exclude. DOCS: https://spacy.io/api/attributeruler#from_disk """ + def load_patterns(p): self.add_patterns(srsly.read_msgpack(p)) diff --git a/spacy/pipeline/entity_linker.py b/spacy/pipeline/entity_linker.py index d92c700ba..2acaee8f5 100644 --- a/spacy/pipeline/entity_linker.py +++ b/spacy/pipeline/entity_linker.py @@ -2,7 +2,7 @@ from typing import Optional, Iterable, Callable, Dict, Iterator, Union, List, Tu from pathlib import Path import srsly import random -from thinc.api import CosineDistance, get_array_module, Model, Optimizer, Config +from thinc.api import CosineDistance, Model, Optimizer, Config from thinc.api import set_dropout_rate import warnings diff --git a/spacy/tests/pipeline/test_attributeruler.py b/spacy/tests/pipeline/test_attributeruler.py index 5fc6faaf0..96361a693 100644 --- a/spacy/tests/pipeline/test_attributeruler.py +++ b/spacy/tests/pipeline/test_attributeruler.py @@ -104,7 +104,11 @@ def test_attributeruler_score(nlp, pattern_dicts): assert doc[3].lemma_ == "cat" assert doc[3].morph_ == "Case=Nom|Number=Sing" - dev_examples = [Example.from_dict(nlp.make_doc("This is a test."), {"lemmas": ["this", "is", "a", "cat", "."]})] + dev_examples = [ + Example.from_dict( + nlp.make_doc("This is a test."), {"lemmas": ["this", "is", "a", "cat", "."]} + ) + ] scores = nlp.evaluate(dev_examples) # "cat" is the only correct lemma assert scores["lemma_acc"] == pytest.approx(0.2) @@ -115,20 +119,14 @@ def test_attributeruler_score(nlp, pattern_dicts): def test_attributeruler_rule_order(nlp): a = AttributeRuler(nlp.vocab) patterns = [ - { - "patterns": [[{"TAG": "VBZ"}]], - "attrs": {"POS": "VERB"}, - }, - { - "patterns": [[{"TAG": "VBZ"}]], - "attrs": {"POS": "NOUN"}, - }, + {"patterns": [[{"TAG": "VBZ"}]], "attrs": {"POS": "VERB"}}, + {"patterns": [[{"TAG": "VBZ"}]], "attrs": {"POS": "NOUN"}}, ] a.add_patterns(patterns) doc = get_doc( nlp.vocab, words=["This", "is", "a", "test", "."], - tags=["DT", "VBZ", "DT", "NN", "."] + tags=["DT", "VBZ", "DT", "NN", "."], ) doc = a(doc) assert doc[1].pos_ == "NOUN" diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 240683f7d..aa8ea6051 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -373,8 +373,7 @@ def test_parse_config_overrides(args, expected): @pytest.mark.parametrize( - "args", - [["--foo"], ["--x.foo", "bar", "--baz"]], + "args", [["--foo"], ["--x.foo", "bar", "--baz"]], ) def test_parse_config_overrides_invalid(args): with pytest.raises(NoSuchOption): @@ -382,8 +381,7 @@ def test_parse_config_overrides_invalid(args): @pytest.mark.parametrize( - "args", - [["--x.foo", "bar", "baz"], ["x.foo"]], + "args", [["--x.foo", "bar", "baz"], ["x.foo"]], ) def test_parse_config_overrides_invalid_2(args): with pytest.raises(SystemExit):