Skip to content

Commit

Permalink
lint: ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pidoux7 committed Jul 3, 2024
1 parent 83ce9f9 commit 9f2951e
Show file tree
Hide file tree
Showing 20 changed files with 10 additions and 80 deletions.
32 changes: 8 additions & 24 deletions docs/scripts/autorefs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def handleMatch(self, m, data) -> Union[Element, EvalIDType]: # type: ignore[ov

return self.makeTag(identifier, text), m.start(0), end

def evalId(
self, data: str, index: int, text: str
) -> EvalIDType: # noqa: N802 (parent's casing)
def evalId(self, data: str, index: int, text: str) -> EvalIDType: # noqa: N802 (parent's casing)
"""Evaluate the id portion of `[ref][id]`.
If `[ref][]` use `[ref]`.
Expand Down Expand Up @@ -157,9 +155,7 @@ def relative_url(url_a: str, url_b: str) -> str:
return f"{relative}#{anchor}"


def fix_ref(
url_mapper: Callable[[str], str], unmapped: List[str]
) -> Callable: # noqa: WPS212,WPS231
def fix_ref(url_mapper: Callable[[str], str], unmapped: List[str]) -> Callable: # noqa: WPS212,WPS231
"""Return a `repl` function for [`re.sub`](https://docs.python.org/3/library/re.html#re.sub).
In our context, we match Markdown references and replace them with HTML links.
Expand Down Expand Up @@ -225,9 +221,7 @@ def fix_refs(html: str, url_mapper: Callable[[str], str]) -> Tuple[str, List[str
class AutorefsExtension(Extension):
"""Extension that inserts auto-references in Markdown."""

def extendMarkdown(
self, md: Markdown
) -> None: # noqa: N802 (casing: parent method's name)
def extendMarkdown(self, md: Markdown) -> None: # noqa: N802 (casing: parent method's name)
"""Register the extension.
Add an instance of our [`AutoRefInlineProcessor`][mkdocs_autorefs.references.AutoRefInlineProcessor] to the Markdown parser.
Expand Down Expand Up @@ -268,9 +262,7 @@ def __init__(self) -> None:
super().__init__()
self._url_map: Dict[str, str] = {}
self._abs_url_map: Dict[str, str] = {}
self.get_fallback_anchor: Optional[
Callable[[str], Optional[str]]
] = None # noqa: WPS234
self.get_fallback_anchor: Optional[Callable[[str], Optional[str]]] = None # noqa: WPS234
self._priority_patterns = None

@property
Expand Down Expand Up @@ -355,9 +347,7 @@ def get_item_url( # noqa: WPS234
"""
return self._get_item_url(identifier, fallback)

def on_config(
self, config: Config, **kwargs
) -> Config: # noqa: W0613,R0201 (unused arguments, cannot be static)
def on_config(self, config: Config, **kwargs) -> Config: # noqa: W0613,R0201 (unused arguments, cannot be static)
"""Instantiate our Markdown extension.
Hook for the [`on_config` event](https://www.mkdocs.org/user-guide/plugins/#on_config).
Expand All @@ -375,9 +365,7 @@ def on_config(
config["markdown_extensions"].append(AutorefsExtension())
return config

def on_page_markdown(
self, markdown: str, page: Page, **kwargs
) -> str: # noqa: W0613 (unused arguments)
def on_page_markdown(self, markdown: str, page: Page, **kwargs) -> str: # noqa: W0613 (unused arguments)
"""Remember which page is the current one.
Arguments:
Expand All @@ -391,9 +379,7 @@ def on_page_markdown(
self.current_page = page.url # noqa: WPS601
return markdown

def on_page_content(
self, html: str, page: Page, **kwargs
) -> str: # noqa: W0613 (unused arguments)
def on_page_content(self, html: str, page: Page, **kwargs) -> str: # noqa: W0613 (unused arguments)
"""Map anchors to URLs.
Hook for the [`on_page_content` event](https://www.mkdocs.org/user-guide/plugins/#on_page_content).
Expand Down Expand Up @@ -431,9 +417,7 @@ def map_urls(self, page: Page, anchor: AnchorLink) -> None:
for child in anchor.children:
self.map_urls(page, child)

def on_post_page(
self, output: str, page: Page, **kwargs
) -> str: # noqa: W0613 (unused arguments)
def on_post_page(self, output: str, page: Page, **kwargs) -> str: # noqa: W0613 (unused arguments)
"""Fix cross-references.
Hook for the [`on_post_page` event](https://www.mkdocs.org/user-guide/plugins/#on_post_page).
Expand Down
1 change: 0 additions & 1 deletion scripts/adicap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def parse_each_dict(df, dictionaryCode: str):
def get_decode_dict(df, dict_keys=["D1", "D2", "D3", "D4", "D5", "D6", "D7"]):
decode_dict = {}
for key in dict_keys:

decode_dict[key] = parse_each_dict(df, dictionaryCode=key)

return decode_dict
Expand Down
2 changes: 1 addition & 1 deletion scripts/conjugate_verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def conjugate_verbs(
output_path: Path = typer.Argument(
"edsnlp/resources/verbs.csv.gz", help="Path to the output CSV table."
)
),
) -> None:
"""
Convenience script to automatically conjugate a set of verbs,
Expand Down
2 changes: 0 additions & 2 deletions scripts/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@


class Entity(BaseModel): # (2)

# OMOP-style attributes
start: int
end: int
Expand All @@ -56,7 +55,6 @@ class Document(BaseModel): # (1)
async def process(
notes: List[str], # (2)
):

documents = []

for doc in nlp.pipe(notes):
Expand Down
1 change: 0 additions & 1 deletion tests/connectors/test_labeltool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


def test_docs2labeltool(nlp):

modifiers = ["negated", "hypothesis", "reported_speech"]

docs = list(nlp.pipe(texts))
Expand Down
4 changes: 0 additions & 4 deletions tests/connectors/test_omop.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def random_text():


def random_note_nlp(text):

ents = []

for match in re.finditer(r"\w+", text):
Expand All @@ -44,7 +43,6 @@ def random_note_nlp(text):

@pytest.fixture
def note():

df = pd.DataFrame(dict(note_text=[random_text() for _ in range(10)]))
df["note_id"] = range(len(df))
df["note_datetime"] = "2021-10-19"
Expand All @@ -54,7 +52,6 @@ def note():

@pytest.fixture
def note_nlp(note):

df = note.copy()
df["ents"] = df.note_text.apply(random_note_nlp)
df = df.explode("ents")
Expand All @@ -77,7 +74,6 @@ def docs(omop: OmopConnector, note, note_nlp):


def test_omop2docs(docs, note, note_nlp):

lexical_variants = note_nlp.groupby("note_id")["lexical_variant"].agg(list)

for doc, text, lvs in zip(docs, note.note_text, lexical_variants):
Expand Down
2 changes: 0 additions & 2 deletions tests/matchers/test_phrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_eds_phrase_matcher(doc, nlp):


def test_offset(blank_nlp):

text = "Ceci est un test de matching"

doc = blank_nlp(text)
Expand All @@ -45,7 +44,6 @@ def test_offset(blank_nlp):


def test_remove(blank_nlp):

pattern = blank_nlp("matching")
pattern2 = blank_nlp("Ceci")

Expand Down
3 changes: 0 additions & 3 deletions tests/pipelines/core/test_contextual_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@

@pytest.mark.parametrize("params,example", list(zip(ALL_PARAMS, EXAMPLES)))
def test_contextual(blank_nlp, params, example):

include_assigned, replace_entity, reduce_mode_stage, reduce_mode_metastase = params

blank_nlp.add_pipe(
Expand Down Expand Up @@ -225,9 +224,7 @@ def test_contextual(blank_nlp, params, example):
assert len(doc.ents) == len(entities)

for entity, ent in zip(entities, doc.ents):

for modifier in entity.modifiers:

assert (
rgetattr(ent, modifier.key) == modifier.value
), f"{modifier.key} labels don't match."
6 changes: 0 additions & 6 deletions tests/pipelines/core/test_normalisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_full_normalization(doc):
@fixture
def nlp_factory(blank_nlp):
def f(a=False, lc=False, q=False, p=False):

if a:
a = dict(accents=accents)
if q:
Expand All @@ -48,7 +47,6 @@ def f(a=False, lc=False, q=False, p=False):


def test_normalization_accents(nlp_factory, text):

nlp = nlp_factory(a=True)
doc = nlp(text)

Expand All @@ -58,7 +56,6 @@ def test_normalization_accents(nlp_factory, text):


def test_normalization_spaces(nlp_factory, text):

nlp = nlp_factory(a=True)
doc = nlp("Phrase avec des espaces \n et un retour à la ligne")

Expand All @@ -67,7 +64,6 @@ def test_normalization_spaces(nlp_factory, text):


def test_normalization_quotes(nlp_factory, text):

nlp = nlp_factory(q=True)
doc = nlp(text)

Expand All @@ -79,7 +75,6 @@ def test_normalization_quotes(nlp_factory, text):


def test_normalization_lowercase(nlp_factory, text):

nlp = nlp_factory(lc=True)
doc = nlp(text)

Expand All @@ -89,7 +84,6 @@ def test_normalization_lowercase(nlp_factory, text):


def test_normalization_pollution(nlp_factory, text):

nlp = nlp_factory(p=True)
doc = nlp(text)

Expand Down
1 change: 0 additions & 1 deletion tests/pipelines/misc/test_consultation_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
@pytest.mark.parametrize("date_pipeline", [True, False])
@pytest.mark.parametrize("example", [cons, cons_town, cons_town_doc])
def test_cons_dates(date_pipeline, example, blank_nlp):

blank_nlp.add_pipe(
"eds.normalizer",
config=dict(lowercase=True, accents=True, quotes=True, pollution=False),
Expand Down
6 changes: 0 additions & 6 deletions tests/pipelines/misc/test_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_section_detection(doc):

@fixture
def sections_factory(blank_nlp):

default_config = dict(
sections=patterns.sections,
add_patterns=True,
Expand All @@ -40,7 +39,6 @@ def sections_factory(blank_nlp):
)

def factory(**kwargs):

config = dict(**default_config)
config.update(kwargs)

Expand All @@ -53,7 +51,6 @@ def factory(**kwargs):


def test_sections(blank_nlp, sections_factory):

blank_nlp.add_pipe("normalizer")

sections = sections_factory()
Expand All @@ -68,16 +65,13 @@ def test_sections(blank_nlp, sections_factory):
doc = sections(doc)

for entity, ent in zip(entities, doc.ents):

for modifier in entity.modifiers:

assert (
getattr(ent._, modifier.key) == modifier.value
), f"{modifier.key} labels don't match."


def test_empty_sections(blank_nlp, sections_factory):

blank_nlp.add_pipe("normalizer")

sections = sections_factory()
Expand Down
1 change: 0 additions & 1 deletion tests/pipelines/ner/disorders/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def check(self):
list(results.keys()),
)
def test_disorder(normalized_nlp, disorder):

result = results[disorder]

expect = DisorderTester(
Expand Down
1 change: 0 additions & 1 deletion tests/pipelines/ner/test_adicap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_scores(blank_nlp):
blank_nlp.add_pipe("eds.adicap")

for example in examples:

text, expected_entities = parse_example(example=example)

doc = blank_nlp(text)
Expand Down
1 change: 0 additions & 1 deletion tests/pipelines/ner/test_adicap_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@


def test_scores(blank_nlp):

blank_nlp.add_pipe("eds.adicap")

for input, expected in zip(examples, expected_outputs):
Expand Down
1 change: 0 additions & 1 deletion tests/pipelines/ner/test_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def testscore_normalization(raw_score: str):
doc = testscore(doc)

for entity, ent in zip(entities, doc.ents):

for modifier in entity.modifiers:
assert (
getattr(ent._, modifier.key) == modifier.value
Expand Down
5 changes: 0 additions & 5 deletions tests/pipelines/qualifiers/test_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

@fixture
def family_factory(blank_nlp):

default_config = dict(
family=None,
termination=None,
Expand All @@ -39,7 +38,6 @@ def family_factory(blank_nlp):
)

def factory(on_ents_only, **kwargs):

config = dict(**default_config)
config.update(kwargs)

Expand All @@ -55,7 +53,6 @@ def factory(on_ents_only, **kwargs):
@mark.parametrize("on_ents_only", [True, False])
@mark.parametrize("use_sections", [True, False])
def test_family(blank_nlp, family_factory, on_ents_only, use_sections):

family = family_factory(
on_ents_only=on_ents_only,
use_sections=use_sections,
Expand All @@ -72,9 +69,7 @@ def test_family(blank_nlp, family_factory, on_ents_only, use_sections):
doc = family(doc)

for entity, ent in zip(entities, doc.ents):

for modifier in entity.modifiers:

assert bool(ent._.family_cues) == (modifier.value in {"FAMILY", True})

assert (
Expand Down
Loading

0 comments on commit 9f2951e

Please sign in to comment.