Skip to content

Commit 89fc794

Browse files
committed
some more clean-up
1 parent 7f5a17e commit 89fc794

6 files changed

Lines changed: 46 additions & 46 deletions

File tree

mlscorecheck/check/bundles/retina/_drishti_gs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def check_drishti_gs_segmentation_aggregated_mos(
144144
timeout: int | None = None,
145145
verbosity: int = 1,
146146
numerical_tolerance: float = NUMERICAL_TOLERANCE,
147-
):
147+
) -> dict:
148148
"""
149149
Testing the scores shared for a set of images with the MoS aggregation.
150150
@@ -212,7 +212,7 @@ def check_drishti_gs_segmentation_aggregated_som(
212212
eps: float,
213213
*,
214214
numerical_tolerance: float = NUMERICAL_TOLERANCE,
215-
):
215+
) -> dict:
216216
"""
217217
Testing the scores shared for a set of images with the SoM aggregation.
218218
@@ -281,7 +281,7 @@ def check_drishti_gs_segmentation_aggregated(
281281
timeout: int | None = None,
282282
verbosity: int = 1,
283283
numerical_tolerance: float = NUMERICAL_TOLERANCE,
284-
):
284+
) -> dict:
285285
"""
286286
Testing the scores shared for a set of images with both the MoS and SoM aggregations.
287287

mlscorecheck/check/bundles/retina/_drive.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ def check_drive_vessel_aggregated_mos_assumption(
122122

123123

124124
def check_drive_vessel_aggregated_som_assumption(
125-
imageset,
125+
imageset: str | list,
126126
assumption: str,
127127
annotator: int,
128128
scores: dict,
129-
eps,
129+
eps: float | dict,
130130
*,
131-
numerical_tolerance=NUMERICAL_TOLERANCE,
132-
):
131+
numerical_tolerance: float = NUMERICAL_TOLERANCE,
132+
) -> dict:
133133
"""
134134
Tests the consistency of scores calculated on the DRIVE dataset using
135135
the score of means aggregation and a particular assumption on the region
@@ -192,10 +192,10 @@ def check_drive_vessel_image_assumption(
192192
assumption: str,
193193
annotator: str,
194194
scores: dict,
195-
eps,
195+
eps: float | dict,
196196
*,
197197
numerical_tolerance: float = NUMERICAL_TOLERANCE,
198-
):
198+
) -> dict:
199199
"""
200200
Testing the scores calculated for one image of the DRIVE dataset with a particular
201201
assumption on the region of evaluation.
@@ -359,10 +359,10 @@ def check_drive_vessel_image(
359359
image_identifier: str,
360360
annotator: str,
361361
scores: dict,
362-
eps,
362+
eps: float | dict,
363363
*,
364364
numerical_tolerance: float = NUMERICAL_TOLERANCE,
365-
):
365+
) -> dict:
366366
"""
367367
Testing the scores calculated for one image of the DRIVE dataset with
368368
both assumptions on the region of evaluation ('fov'/'all').

mlscorecheck/individual/_check_scores_tptn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def check_any_zero_division(sols: list) -> bool:
322322
return any(sol.get("message") == "zero division" for sol in sols)
323323

324324

325-
def update_tptn(tp, tn, sols: list):
325+
def update_tptn(tp: Interval | IntervalUnion, tn: Interval | IntervalUnion, sols: list) -> tuple[Interval | IntervalUnion, Interval | IntervalUnion]:
326326
"""
327327
Updates the tp and tn intervals based on the solutions
328328

mlscorecheck/individual/_interval.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def __repr__(self) -> str:
318318
"""
319319
return str(f"({str(self.lower_bound)}, {str(self.upper_bound)})")
320320

321-
def __eq__(self, other) -> bool:
321+
def __eq__(self, other: object) -> bool:
322322
"""
323323
Equality operator
324324
@@ -332,7 +332,7 @@ def __eq__(self, other) -> bool:
332332
return False
333333
return bool(self.lower_bound == other.lower_bound and self.upper_bound == other.upper_bound)
334334

335-
def __ne__(self, other) -> bool:
335+
def __ne__(self, other: object) -> bool:
336336
"""
337337
Non-equality operator
338338
@@ -476,7 +476,7 @@ def simplify(self) -> None:
476476

477477
self.intervals = final_intervals
478478

479-
def contains(self, value) -> bool:
479+
def contains(self, value: float | int) -> bool:
480480
"""
481481
Check if the interval contains the value
482482
@@ -488,7 +488,7 @@ def contains(self, value) -> bool:
488488
"""
489489
return any(interval.contains(value) for interval in self.intervals)
490490

491-
def intersection(self, other):
491+
def intersection(self, other: "Interval | IntervalUnion") -> "IntervalUnion":
492492
"""
493493
Returns the intersection of two intervals
494494
@@ -521,7 +521,7 @@ def integer(self) -> bool:
521521

522522
return any(interval.integer() for interval in self.intervals)
523523

524-
def shrink_to_integers(self):
524+
def shrink_to_integers(self) -> "IntervalUnion":
525525
"""
526526
Shrinking the interval to integer boundaries
527527
@@ -550,7 +550,7 @@ def is_empty(self) -> bool:
550550
return True
551551
return all(interval.is_empty() for interval in self.intervals)
552552

553-
def __add__(self, other):
553+
def __add__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
554554
"""
555555
The addition operator
556556
@@ -569,7 +569,7 @@ def __add__(self, other):
569569

570570
return IntervalUnion(intervals)
571571

572-
def __radd__(self, other):
572+
def __radd__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
573573
"""
574574
The right hand addition
575575
@@ -581,7 +581,7 @@ def __radd__(self, other):
581581
"""
582582
return self + other
583583

584-
def __sub__(self, other):
584+
def __sub__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
585585
"""
586586
The subtraction operator
587587
@@ -601,7 +601,7 @@ def __sub__(self, other):
601601

602602
return IntervalUnion(intervals)
603603

604-
def __rsub__(self, other):
604+
def __rsub__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
605605
"""
606606
The right hand subtraction
607607
@@ -613,7 +613,7 @@ def __rsub__(self, other):
613613
"""
614614
return -1 * self + other
615615

616-
def __mul__(self, other):
616+
def __mul__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
617617
"""
618618
The multiplication operator
619619
@@ -634,7 +634,7 @@ def __mul__(self, other):
634634

635635
return IntervalUnion(intervals)
636636

637-
def __rmul__(self, other):
637+
def __rmul__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
638638
"""
639639
The right hand multiplication operator
640640
@@ -646,7 +646,7 @@ def __rmul__(self, other):
646646
"""
647647
return self.__mul__(other)
648648

649-
def __truediv__(self, other):
649+
def __truediv__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
650650
"""
651651
The division operator
652652
@@ -678,7 +678,7 @@ def __truediv__(self, other):
678678

679679
return IntervalUnion(intervals)
680680

681-
def __rtruediv__(self, other):
681+
def __rtruediv__(self, other: "int | float | Interval | IntervalUnion") -> "IntervalUnion":
682682
"""
683683
The right hand division operator
684684
@@ -696,7 +696,7 @@ def __rtruediv__(self, other):
696696

697697
return other / self
698698

699-
def __neg__(self):
699+
def __neg__(self) -> "IntervalUnion":
700700
"""
701701
The negation operator
702702
@@ -716,7 +716,7 @@ def __repr__(self) -> str:
716716
[f"({interval.lower_bound}, {interval.upper_bound})" for interval in self.intervals]
717717
)
718718

719-
def __eq__(self, other) -> bool:
719+
def __eq__(self, other: object) -> bool:
720720
"""
721721
Equality operator
722722
@@ -740,7 +740,7 @@ def __eq__(self, other) -> bool:
740740

741741
return True
742742

743-
def __ne__(self, other) -> bool:
743+
def __ne__(self, other: object) -> bool:
744744
"""
745745
Non-equality operator
746746
@@ -752,7 +752,7 @@ def __ne__(self, other) -> bool:
752752
"""
753753
return not self.__eq__(other)
754754

755-
def __pow__(self, other):
755+
def __pow__(self, other: float | int) -> "IntervalUnion":
756756
"""
757757
The power operation on the interval union
758758
@@ -764,7 +764,7 @@ def __pow__(self, other):
764764
"""
765765
return IntervalUnion([interval**other for interval in self.intervals])
766766

767-
def representing_int(self):
767+
def representing_int(self) -> int | None:
768768
"""
769769
Returns a representative integer
770770

mlscorecheck/individual/_problem_generator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
"generate_problem_and_scores",
1313
"generate_multiclass_dataset",
1414
"sample_multiclass_dataset",
15-
"create_confusion_matrix",
16-
]
15+
"create_confusion_matrix",]
1716

1817

1918
def generate_problem_and_scores(
2019
rounding_decimals: int = 4,
2120
*,
22-
random_state=None,
21+
random_state: int | np.random.RandomState | None = None,
2322
p_bounds: tuple[int, int] = (10, 100),
2423
n_bounds: tuple[int, int] = (10, 100),
2524
available_scores: list | None = None,
@@ -60,7 +59,7 @@ def generate_1_problem(
6059
max_n: int = 1000,
6160
zeros: list | None = None,
6261
add_complements: bool = False,
63-
random_state=None,
62+
random_state: int | None = None,
6463
) -> tuple[dict, dict]:
6564
"""
6665
Generates a random problem

mlscorecheck/symbolic/_sage_algebra.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
__all__ = ["SageAlgebra"]
99

1010
import importlib
11+
from typing import Any
1112

1213
from ._algebra import Algebra
1314

@@ -17,7 +18,7 @@ class SageAlgebra(Algebra): # pragma: no cover
1718
The required algebra driven by sage
1819
"""
1920

20-
def __init__(self): # pragma: no cover
21+
def __init__(self) -> None: # pragma: no cover
2122
"""
2223
Constructor of the algebra
2324
"""
@@ -26,7 +27,7 @@ def __init__(self): # pragma: no cover
2627
self.algebra = importlib.import_module("sage.all") # pragma: no cover
2728
self.sqrt = self.algebra.sqrt # pragma: no cover
2829

29-
def create_symbol(self, name, **kwargs): # pragma: no cover
30+
def create_symbol(self, name: str, **kwargs) -> Any: # pragma: no cover
3031
"""
3132
Create a symbol in the algebra with the specified name and assumptions
3233
@@ -55,7 +56,7 @@ def create_symbol(self, name, **kwargs): # pragma: no cover
5556

5657
return var # pragma: no cover
5758

58-
def num_denom(self, expression): # pragma: no cover
59+
def num_denom(self, expression: Any) -> tuple[Any, Any]: # pragma: no cover
5960
"""
6061
Extract the numerator and denominator
6162
@@ -67,7 +68,7 @@ def num_denom(self, expression): # pragma: no cover
6768
"""
6869
return expression.numerator(), expression.denominator() # pragma: no cover
6970

70-
def simplify(self, expression): # pragma: no cover
71+
def simplify(self, expression: Any) -> Any: # pragma: no cover
7172
"""
7273
Simplify the expression
7374
@@ -79,7 +80,7 @@ def simplify(self, expression): # pragma: no cover
7980
"""
8081
return self.algebra.factor(expression) # pragma: no cover
8182

82-
def solve(self, equation, var, **kwargs): # pragma: no cover
83+
def solve(self, equation: Any, var: Any, **kwargs) -> list[dict]: # pragma: no cover
8384
"""
8485
Solve an equation for a variable
8586
@@ -98,7 +99,7 @@ def solve(self, equation, var, **kwargs): # pragma: no cover
9899
solutions.append(solution) # pragma: no cover
99100
return solutions # pragma: no cover
100101

101-
def subs(self, expression, subs_dict): # pragma: no cover
102+
def subs(self, expression: Any, subs_dict: dict) -> Any: # pragma: no cover
102103
"""
103104
Substitute a substitution into the expression
104105
@@ -123,7 +124,7 @@ def args(self, expression) -> list: # pragma: no cover
123124
"""
124125
return list(expression.args()) # pragma: no cover
125126

126-
def is_trivial(self, expression) -> bool: # pragma: no cover
127+
def is_trivial(self, expression: Any) -> bool: # pragma: no cover
127128
"""
128129
Checks if the expression is trivial
129130
@@ -135,7 +136,7 @@ def is_trivial(self, expression) -> bool: # pragma: no cover
135136
"""
136137
return True if expression is None else expression.is_trivially_equal(1) # pragma: no cover
137138

138-
def is_root(self, expression) -> bool: # pragma: no cover
139+
def is_root(self, expression: Any) -> bool: # pragma: no cover
139140
"""
140141
Checks if the expression is a root
141142
@@ -151,7 +152,7 @@ def is_root(self, expression) -> bool: # pragma: no cover
151152
return True # pragma: no cover
152153
return False # pragma: no cover
153154

154-
def is_power(self, expression) -> bool: # pragma: no cover
155+
def is_power(self, expression: Any) -> bool: # pragma: no cover
155156
"""
156157
Checks whether the expression is a power
157158
@@ -166,7 +167,7 @@ def is_power(self, expression) -> bool: # pragma: no cover
166167
and expression.operator().__qualname__ == "pow"
167168
) # pragma: no cover
168169

169-
def is_division(self, expression) -> bool: # pragma: no cover
170+
def is_division(self, expression: Any) -> bool: # pragma: no cover
170171
"""
171172
Checks whether the expression is a division
172173
@@ -198,7 +199,7 @@ def is_division(self, expression) -> bool: # pragma: no cover
198199
return True # pragma: no cover
199200
return False # pragma: no cover
200201

201-
def operands(self, expression) -> list: # pragma: no cover
202+
def operands(self, expression: Any) -> list: # pragma: no cover
202203
"""
203204
Returns the list of operands
204205
@@ -210,7 +211,7 @@ def operands(self, expression) -> list: # pragma: no cover
210211
"""
211212
return list(expression.operands()) # pragma: no cover
212213

213-
def free_symbols(self, expression) -> list: # pragma: no cover
214+
def free_symbols(self, expression: Any) -> list: # pragma: no cover
214215
"""
215216
Get all free symbols in an expression
216217

0 commit comments

Comments
 (0)