Skip to content

Commit

Permalink
fix: further typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Palucha authored and paluchasz committed Sep 25, 2024
1 parent e087e90 commit 5f6da5f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
24 changes: 13 additions & 11 deletions kazu/annotation/label_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
),
},
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions kazu/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5f6da5f

Please sign in to comment.