Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/archunitpython/common/fluentapi/checkable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from archunitpython.common.logging.types import LoggingOptions


@dataclass(frozen=True)
@dataclass(frozen=True, slots=True)
class CheckOptions:
"""Options for controlling rule check execution."""

Expand Down
2 changes: 1 addition & 1 deletion src/archunitpython/common/logging/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
LogLevel = Literal["debug", "info", "warn", "error"]


@dataclass(frozen=True)
@dataclass(frozen=True, slots=True)
class LoggingOptions:
"""Options for controlling logging during architecture checks."""

Expand Down
4 changes: 2 additions & 2 deletions src/archunitpython/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
MatchType = Literal["exact", "partial"]


@dataclass(frozen=True)
@dataclass(frozen=True, slots=True)
class PatternMatchingOptions:
"""Options controlling how a pattern is matched against file paths."""

target: MatchTarget = "path"
matching: MatchType = "partial"


@dataclass(frozen=True)
@dataclass(frozen=True, slots=True)
class Filter:
"""A compiled regex filter with matching options."""

Expand Down
18 changes: 6 additions & 12 deletions src/archunitpython/common/util/declaration_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass


@dataclass
@dataclass(slots=True)
class DeclarationCounts:
"""Counts of different declaration types in a Python file."""

Expand Down Expand Up @@ -88,24 +88,18 @@ def count_declarations(source: str) -> DeclarationCounts:
if is_abstract_method(item):
counts.abstract_methods += 1

elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
for node in tree.body:
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
# Only count module-level functions
if _is_module_level(node, tree):
counts.total += 1
counts.functions += 1

elif isinstance(node, ast.Assign) and _is_module_level(node, tree):
counts.functions += 1
counts.total += 1
if isinstance(node, ast.Assign):
counts.variables += 1
counts.total += 1

return counts


def _is_module_level(node: ast.AST, tree: ast.Module) -> bool:
"""Check if a node is directly in the module body."""
return node in tree.body


def _get_name(node: ast.expr) -> str:
"""Extract a name from an AST node."""
if isinstance(node, ast.Name):
Expand Down