Skip to content

Commit

Permalink
Simplify hints using Sequence for Union[Tuple, List]
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen committed May 24, 2023
1 parent f242a98 commit 7c3c5dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 45 deletions.
6 changes: 4 additions & 2 deletions annif/corpus/skos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
Dict,
Iterator,
List,
Sequence,
Set,
Tuple,
Union,
)

Expand Down Expand Up @@ -118,7 +118,9 @@ def concepts(self) -> Iterator[URIRef]:
yield concept

def get_concept_labels(
self, concept: URIRef, label_types: Union[Tuple[URIRef, URIRef], List[URIRef]]
self,
concept: URIRef,
label_types: Sequence[URIRef],
) -> Union[DefaultDict[str, List[str]], DefaultDict[None, List[str]]]:
"""return all the labels of the given concept with the given label
properties as a dict-like object where the keys are language codes
Expand Down
47 changes: 4 additions & 43 deletions annif/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Sequence, Union

import numpy as np
import scipy.sparse
Expand Down Expand Up @@ -90,46 +90,7 @@ def evaluate_many(
suggestion_batch: Union[
List[List[SubjectSuggestion]], SuggestionBatch, List[Iterator[Any]]
],
gold_subject_batch: Union[
Tuple[SubjectSet, SubjectSet, SubjectSet],
Tuple[SubjectSet, SubjectSet, SubjectSet, SubjectSet],
Tuple[SubjectSet, SubjectSet],
Tuple[
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
SubjectSet,
],
List[SubjectSet],
],
gold_subject_batch: Sequence[SubjectSet],
) -> None:
if not isinstance(suggestion_batch, SuggestionBatch):
suggestion_batch = SuggestionBatch.from_sequence(
Expand All @@ -150,7 +111,7 @@ def _evaluate_samples(
self,
y_true: csr_array,
y_pred: csr_array,
metrics: Union[Tuple[str, str], Tuple[()], List[str]] = [],
metrics: Sequence[str] = [],
) -> Dict[str, Union[np.float64, float, int]]:
y_pred_binary = y_pred > 0.0

Expand Down Expand Up @@ -285,7 +246,7 @@ def output_result_per_subject(

def results(
self,
metrics: Union[Tuple[str, str], Tuple[()], List[str]] = [],
metrics: Sequence[str] = [],
results_file: Optional[Union[LazyFile, TextIOWrapper]] = None,
language: Optional[str] = None,
) -> Dict[str, Union[np.float64, float]]:
Expand Down

0 comments on commit 7c3c5dc

Please sign in to comment.