diff --git a/kazu/annotation/label_studio.py b/kazu/annotation/label_studio.py index 546ed70e..fa71946f 100644 --- a/kazu/annotation/label_studio.py +++ b/kazu/annotation/label_studio.py @@ -147,14 +147,16 @@ def _create_mapping_region( "start": span.start, "end": span.end, "text": match, - "taxonomy": sorted( - set( - (mapping.source, f"{mapping.default_label}|{mapping.idx}") - for mapping in ent.mappings + "taxonomy": ( + sorted( + set( + (mapping.source, f"{mapping.default_label}|{mapping.idx}") + for mapping in ent.mappings + ) ) - ) - if len(ent.mappings) > 0 - else [("None", "unmapped|unmapped")], + if len(ent.mappings) > 0 + else [("None", "unmapped|unmapped")] + ), }, } @@ -286,7 +288,7 @@ def _create_non_contiguous_entities(self, region_id: str) -> Iterable[Entity]: mappings=mappings, ) - def _create_contiguous_entity(self, label, region_id, span): + def _create_contiguous_entity(self, label: str, region_id: str, span: CharSpan) -> Entity: single_span = frozenset([span]) mappings = deepcopy(self.id_to_mappings.get(region_id, set())) return Entity( @@ -514,7 +516,7 @@ def project_id(self) -> int: f"more than one project with name: {self.project_name} found in Label Studio" ) - def delete_project_if_exists(self): + def delete_project_if_exists(self) -> None: try: resp = requests.delete( f"{self.url}/api/projects/{self.project_id}", @@ -553,7 +555,7 @@ def update_view(self, view: LabelStudioAnnotationView, docs: list[Document]) -> def update_view(self, view: LabelStudioAnnotationView, docs: list[set[Document]]) -> None: pass - def update_view(self, view, docs): + def update_view(self, view, docs): # type: ignore[no-untyped-def] """Update the view of a label studio project. :param view: @@ -590,7 +592,7 @@ def update_tasks(self, docs: list[Document]) -> None: def update_tasks(self, docs: list[set[Document]]) -> None: pass - def update_tasks(self, docs): + def update_tasks(self, docs): # type: ignore[no-untyped-def] """Add tasks to a label studio project. :param docs: either a list of kazu documents, or a list of a set of kazu diff --git a/kazu/utils/utils.py b/kazu/utils/utils.py index 8a26d743..13ef0c12 100644 --- a/kazu/utils/utils.py +++ b/kazu/utils/utils.py @@ -150,7 +150,9 @@ def _create_ngrams_iter(tokens: Sequence[str], n: int) -> Iterable[Sequence[str] pass -def _create_ngrams_iter(tokens, n=2): +def _create_ngrams_iter( + tokens: Union[str, Sequence[str]], n: int = 2 +) -> Union[Iterable[str], Iterable[Sequence[str]]]: """Yields ngrams of the input as a sequence of strings. Tokens can be a single string where each token is a character, or an Iterable of @@ -182,13 +184,13 @@ def create_word_ngrams(s: str, n: int = 2) -> list[str]: class Singleton(type): _instances: dict[type, Any] = {} - def __call__(cls, *args, **kwargs): + def __call__(cls, *args: Any, **kwargs: Any) -> Any: if cls not in cls._instances: cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] @staticmethod - def clear_all(): + def clear_all() -> None: logger.warning( "When clearing singletons, check that instances of classes with metaclass=Singleton are " "not used as class fields, as this will cause unexpected behaviour. Also note that any existing " diff --git a/pyproject.toml b/pyproject.toml index 7eadb274..bc55fbbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -216,10 +216,8 @@ module = [ "kazu.utils.build_and_test_model_packs", # 5 "kazu.linking.sapbert.train", # 4 "kazu.annotation.acceptance_test", # 4 - "kazu.utils.utils", # 3 "kazu.utils.spacy_pipeline", # 2 "kazu.distillation.tiny_transformers", # 2 - "kazu.annotation.label_studio", # 2 "kazu.distillation.metrics", # 1 ] # we had a bunch of these in the codebase before we moved to a 'strict' mypy config, and it was too many