Fix mypy errors.

This commit is contained in:
Raphael Mitsch 2022-12-14 12:10:39 +01:00
parent 51c485da09
commit 581c2fd40f
2 changed files with 5 additions and 3 deletions

View File

@ -1,5 +1,5 @@
from pathlib import Path
from typing import Optional, Callable, Iterable, List, Tuple, Generator, Iterator
from typing import Optional, Callable, Iterable, List, Tuple, Iterator
from thinc.types import Floats2d
from thinc.api import chain, list2ragged, reduce_mean, residual
from thinc.api import Model, Maxout, Linear, tuplify, Ragged
@ -136,7 +136,7 @@ def create_candidates() -> Callable[[KnowledgeBase, Span], Iterable[Candidate]]:
@registry.misc("spacy.CandidateAllGenerator.v1")
def create_candidates_all() -> Callable[
[KnowledgeBase, Generator[Iterable[Span], None, None]],
[KnowledgeBase, Iterator[Doc]],
Iterator[Iterable[Iterable[Candidate]]],
]:
return get_candidates_all

View File

@ -477,7 +477,9 @@ class EntityLinker(TrainablePipe):
RETURN (doc): Doc instance with only valid entities (i.e. those to retrieve candidates for).
"""
_doc = doc.copy()
_doc.ents = [doc.ents[i] for i in valid_ent_idx]
# mypy complains about mismatching types here (Tuple[str] vs. Tuple[str, ...]), which isn't correct and
# probably an artifact of a misreading of the Cython code.
_doc.ents = tuple([doc.ents[i] for i in valid_ent_idx]) # type: ignore
return _doc
all_ent_cands = self.get_candidates_all(