diff --git a/spacy/ml/models/entity_linker.py b/spacy/ml/models/entity_linker.py index 99cc31125..d683a8fe7 100644 --- a/spacy/ml/models/entity_linker.py +++ b/spacy/ml/models/entity_linker.py @@ -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 diff --git a/spacy/pipeline/entity_linker.py b/spacy/pipeline/entity_linker.py index 25fb654ac..6d2a114cb 100644 --- a/spacy/pipeline/entity_linker.py +++ b/spacy/pipeline/entity_linker.py @@ -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(