Fix mypy error.

This commit is contained in:
Raphael Mitsch 2023-03-05 14:33:32 +01:00
parent 5f40b3e523
commit 670e1ca7c5
2 changed files with 7 additions and 0 deletions

View File

@ -952,6 +952,7 @@ class Errors(metaclass=ErrorsWithCodes):
"with `displacy.serve(doc, port=port)`")
E1050 = ("Port {port} is already in use. Please specify an available port with `displacy.serve(doc, port=port)` "
"or use `auto_switch_port=True` to pick an available port automatically.")
E1051 = ("Expected `entity_id` to be of type {should_type}, but is of type {is_type}.")
# v4 error strings
E4000 = ("Expected a Doc as input, but got: '{type}'")

View File

@ -1,6 +1,8 @@
import abc
from typing import List, Union, Callable
from ..errors import Errors
class Candidate(abc.ABC):
"""A `Candidate` object refers to a textual mention that may or may not be resolved
@ -97,6 +99,10 @@ class InMemoryCandidate(Candidate):
)
self._hash_to_str = hash_to_str
self._entity_freq = entity_freq
if not isinstance(self._entity_id, int):
raise ValueError(
Errors.E1051.format(should_type="int", is_type=str(type(entity_id)))
)
self._entity_id_str = self._hash_to_str(self._entity_id)
@property