Skip to content

Commit d69666b

Browse files
fix: lint issues
1 parent 5bc8b8e commit d69666b

File tree

5 files changed

+80
-25
lines changed

5 files changed

+80
-25
lines changed

src/archunitpython/files/fluentapi/files.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from __future__ import annotations
1212

13+
from collections.abc import Sequence
14+
1315
from archunitpython.common.assertion.violation import EmptyTestViolation, Violation
1416
from archunitpython.common.extraction.extract_graph import extract_graph
1517
from archunitpython.common.fluentapi.checkable import CheckOptions
@@ -18,6 +20,7 @@
1820
from archunitpython.common.projection.project_cycles import project_cycles
1921
from archunitpython.common.projection.project_edges import project_edges
2022
from archunitpython.common.projection.project_nodes import project_to_nodes
23+
from archunitpython.common.projection.types import ProjectedNode
2124
from archunitpython.common.regex_factory import RegexFactory
2225
from archunitpython.common.types import Filter, Pattern
2326
from archunitpython.files.assertion.custom_file_logic import (
@@ -257,7 +260,11 @@ def in_path(self, path: Pattern) -> "DependOnFileCondition":
257260
)
258261

259262

260-
def _get_filtered_nodes(project_path, filters, options):
263+
def _get_filtered_nodes(
264+
project_path: str | None,
265+
filters: list[Filter],
266+
options: CheckOptions | None,
267+
) -> list[ProjectedNode]:
261268
"""Extract graph and get nodes matching filters."""
262269
graph = extract_graph(project_path, options=options)
263270
nodes = project_to_nodes(graph)
@@ -266,7 +273,12 @@ def _get_filtered_nodes(project_path, filters, options):
266273
return [n for n in nodes if matches_all_patterns(n.label, filters)]
267274

268275

269-
def _check_empty_test(filtered_items, filters, is_negated, options):
276+
def _check_empty_test(
277+
filtered_items: Sequence[object],
278+
filters: list[Filter],
279+
is_negated: bool,
280+
options: CheckOptions | None,
281+
) -> list[Violation] | None:
270282
"""Check for empty test condition."""
271283
if not filtered_items and not (options and options.allow_empty_tests):
272284
return [

src/archunitpython/metrics/fluentapi/export_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MetricsExporter:
2222

2323
@staticmethod
2424
def export_as_html(
25-
data: dict,
25+
data: dict[str, object],
2626
options: ExportOptions | None = None,
2727
) -> str:
2828
"""Export metric data as an HTML report.

src/archunitpython/metrics/fluentapi/metrics.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from __future__ import annotations
1010

11-
from typing import Callable
11+
from typing import Any, Callable
1212

1313
from archunitpython.common.assertion.violation import Violation
1414
from archunitpython.common.fluentapi.checkable import CheckOptions
@@ -155,7 +155,7 @@ def functions(self) -> "FileMetricThresholdBuilder":
155155

156156

157157
class ClassMetricThresholdBuilder:
158-
def __init__(self, project_path, filters, metric) -> None:
158+
def __init__(self, project_path: str | None, filters: list[Filter], metric: Any) -> None:
159159
self._project_path = project_path
160160
self._filters = filters
161161
self._metric = metric
@@ -189,12 +189,19 @@ def should_be_above_or_equal(self, threshold: float) -> "ClassMetricCondition":
189189
class ClassMetricCondition:
190190
"""Checkable that verifies a class-level metric threshold."""
191191

192-
def __init__(self, project_path, filters, metric, threshold, comparison) -> None:
192+
def __init__(
193+
self,
194+
project_path: str | None,
195+
filters: list[Filter],
196+
metric: Any,
197+
threshold: float,
198+
comparison: MetricComparison,
199+
) -> None:
193200
self._project_path = project_path
194201
self._filters = filters
195202
self._metric = metric
196203
self._threshold = threshold
197-
self._comparison: MetricComparison = comparison
204+
self._comparison = comparison
198205

199206
def check(self, options: CheckOptions | None = None) -> list[Violation]:
200207
classes = _get_filtered_classes(self._project_path, self._filters)
@@ -218,7 +225,7 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
218225

219226

220227
class FileMetricThresholdBuilder:
221-
def __init__(self, project_path, filters, metric) -> None:
228+
def __init__(self, project_path: str | None, filters: list[Filter], metric: Any) -> None:
222229
self._project_path = project_path
223230
self._filters = filters
224231
self._metric = metric
@@ -242,7 +249,14 @@ def should_be_below_or_equal(self, threshold: float) -> "FileMetricCondition":
242249
class FileMetricCondition:
243250
"""Checkable that verifies a file-level metric threshold."""
244251

245-
def __init__(self, project_path, filters, metric, threshold, comparison) -> None:
252+
def __init__(
253+
self,
254+
project_path: str | None,
255+
filters: list[Filter],
256+
metric: Any,
257+
threshold: float,
258+
comparison: MetricComparison,
259+
) -> None:
246260
self._project_path = project_path
247261
self._filters = filters
248262
self._metric = metric
@@ -288,7 +302,7 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
288302

289303

290304
class LCOMMetricsBuilder:
291-
def __init__(self, project_path, filters) -> None:
305+
def __init__(self, project_path: str | None, filters: list[Filter]) -> None:
292306
self._project_path = project_path
293307
self._filters = filters
294308

@@ -321,7 +335,7 @@ def lcomstar(self) -> "ClassMetricThresholdBuilder":
321335

322336

323337
class DistanceMetricsBuilder:
324-
def __init__(self, project_path, filters) -> None:
338+
def __init__(self, project_path: str | None, filters: list[Filter]) -> None:
325339
self._project_path = project_path
326340
self._filters = filters
327341

@@ -348,7 +362,7 @@ def not_in_zone_of_uselessness(self) -> "ZoneCondition":
348362

349363

350364
class DistanceThresholdBuilder:
351-
def __init__(self, project_path, filters, metric_attr) -> None:
365+
def __init__(self, project_path: str | None, filters: list[Filter], metric_attr: str) -> None:
352366
self._project_path = project_path
353367
self._filters = filters
354368
self._metric_attr = metric_attr
@@ -375,7 +389,14 @@ def should_be_above(self, threshold: float) -> "DistanceCondition":
375389
class DistanceCondition:
376390
"""Checkable for distance metric thresholds."""
377391

378-
def __init__(self, project_path, filters, metric_attr, threshold, comparison) -> None:
392+
def __init__(
393+
self,
394+
project_path: str | None,
395+
filters: list[Filter],
396+
metric_attr: str,
397+
threshold: float,
398+
comparison: MetricComparison,
399+
) -> None:
379400
self._project_path = project_path
380401
self._filters = filters
381402
self._metric_attr = metric_attr
@@ -408,7 +429,7 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
408429
class ZoneCondition:
409430
"""Checkable for zone detection (pain/uselessness)."""
410431

411-
def __init__(self, project_path, filters, zone_type) -> None:
432+
def __init__(self, project_path: str | None, filters: list[Filter], zone_type: str) -> None:
412433
self._project_path = project_path
413434
self._filters = filters
414435
self._zone_type = zone_type
@@ -444,7 +465,14 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
444465

445466

446467
class CustomMetricsBuilder:
447-
def __init__(self, project_path, filters, name, description, calculation) -> None:
468+
def __init__(
469+
self,
470+
project_path: str | None,
471+
filters: list[Filter],
472+
name: str,
473+
description: str,
474+
calculation: Callable[[ClassInfo], float],
475+
) -> None:
448476
self._project_path = project_path
449477
self._filters = filters
450478
self._name = name
@@ -486,13 +514,21 @@ def should_satisfy(
486514
class CustomMetricCondition:
487515
"""Checkable for custom metric thresholds."""
488516

489-
def __init__(self, project_path, filters, name, calculation, threshold, comparison) -> None:
517+
def __init__(
518+
self,
519+
project_path: str | None,
520+
filters: list[Filter],
521+
name: str,
522+
calculation: Callable[[ClassInfo], float],
523+
threshold: float,
524+
comparison: MetricComparison,
525+
) -> None:
490526
self._project_path = project_path
491527
self._filters = filters
492528
self._name = name
493529
self._calculation = calculation
494530
self._threshold = threshold
495-
self._comparison: MetricComparison = comparison
531+
self._comparison = comparison
496532

497533
def check(self, options: CheckOptions | None = None) -> list[Violation]:
498534
classes = _get_filtered_classes(self._project_path, self._filters)
@@ -518,7 +554,14 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
518554
class CustomAssertionCondition:
519555
"""Checkable for custom metric assertions."""
520556

521-
def __init__(self, project_path, filters, name, calculation, assertion) -> None:
557+
def __init__(
558+
self,
559+
project_path: str | None,
560+
filters: list[Filter],
561+
name: str,
562+
calculation: Callable[[ClassInfo], float],
563+
assertion: Callable[[float, ClassInfo], bool],
564+
) -> None:
522565
self._project_path = project_path
523566
self._filters = filters
524567
self._name = name

src/archunitpython/slices/fluentapi/slices.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
from archunitpython.common.extraction.extract_graph import extract_graph
1717
from archunitpython.common.fluentapi.checkable import CheckOptions
1818
from archunitpython.common.projection.project_edges import project_edges
19+
from archunitpython.common.projection.types import MapFunction
1920
from archunitpython.slices.assertion.admissible_edges import (
2021
CoherenceOptions,
21-
Rule,
2222
gather_positive_violations,
2323
gather_violations,
2424
)
2525
from archunitpython.slices.projection.slicing_projections import (
2626
slice_by_pattern,
2727
slice_by_regex,
2828
)
29-
from archunitpython.slices.uml.generate_rules import generate_rule
29+
from archunitpython.slices.uml.generate_rules import Rule, generate_rule
3030

3131

3232
def project_slices(project_path: str | None = None) -> "SliceConditionBuilder":
@@ -174,7 +174,7 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
174174
edges, rules, contained_nodes, self._coherence_options
175175
)
176176

177-
def _get_mapper(self):
177+
def _get_mapper(self) -> MapFunction:
178178
if self._pattern:
179179
return slice_by_pattern(self._pattern)
180180
elif self._regex:
@@ -210,7 +210,7 @@ def check(self, options: CheckOptions | None = None) -> list[Violation]:
210210
forbidden_rule = Rule(source=self._source, target=self._target)
211211
return gather_violations(edges, [forbidden_rule])
212212

213-
def _get_mapper(self):
213+
def _get_mapper(self) -> MapFunction:
214214
if self._pattern:
215215
return slice_by_pattern(self._pattern)
216216
elif self._regex:

src/archunitpython/testing/assertion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from archunitpython.common.assertion.violation import Violation
6-
from archunitpython.common.fluentapi.checkable import CheckOptions
6+
from archunitpython.common.fluentapi.checkable import Checkable, CheckOptions
77
from archunitpython.testing.common.violation_factory import ViolationFactory
88

99

@@ -30,7 +30,7 @@ def format_violations(violations: list[Violation]) -> str:
3030

3131

3232
def assert_passes(
33-
checkable: object,
33+
checkable: Checkable,
3434
options: CheckOptions | None = None,
3535
) -> None:
3636
"""Assert that an architecture rule passes (no violations).
@@ -42,6 +42,6 @@ def assert_passes(
4242
Raises:
4343
AssertionError: If the rule has violations.
4444
"""
45-
violations = checkable.check(options) # type: ignore[union-attr]
45+
violations = checkable.check(options)
4646
if violations:
4747
raise AssertionError(format_violations(violations))

0 commit comments

Comments
 (0)