Skip to content

Commit 04ec0d9

Browse files
committed
fix(types): remove SchErrAggEntry and SchemaErrorAggregator from mixin, rename with ApatheticSchema_ prefix
- Remove SchErrAggEntry and SchemaErrorAggregator from ApatheticSchema_Internal_Types mixin class - Rename ApatheticSchema_Internal_SchErrAggEntry to ApatheticSchema_SchErrAggEntry - Rename ApatheticSchema_Internal_SchemaErrorAggregator to ApatheticSchema_SchemaErrorAggregator - Export types with ApatheticSchema_ prefix (without Internal_) in __init__.py - Update all references in warn_keys_once.py and flush_schema_aggregators.py - Update test files to use new type names
1 parent 08de031 commit 04ec0d9

File tree

6 files changed

+50
-49
lines changed

6 files changed

+50
-49
lines changed

src/apathetic_schema/__init__.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
if TYPE_CHECKING:
77
from .namespace import apathetic_schema as _apathetic_schema_class
8-
from .types import (
9-
ApatheticSchema_Internal_SchemaErrorAggregator,
10-
ApatheticSchema_Internal_SchErrAggEntry,
11-
)
8+
9+
# Import types for export (available at both type checking and runtime)
10+
from .types import (
11+
ApatheticSchema_SchemaErrorAggregator,
12+
ApatheticSchema_SchErrAggEntry,
13+
)
14+
1215

1316
# Get reference to the namespace class
1417
# In stitched mode: class is already defined in namespace.py (executed before this)
@@ -51,24 +54,18 @@
5154
AGG_STRICT_WARN = apathetic_schema.AGG_STRICT_WARN
5255
AGG_WARN = apathetic_schema.AGG_WARN
5356

54-
# Export type aliases and dataclasses from apathetic_schema class
55-
# For type checking, use the module-level type alias directly
56-
# At runtime, use the class attribute (which references the same type)
57-
if TYPE_CHECKING:
58-
SchErrAggEntry = ApatheticSchema_Internal_SchErrAggEntry
59-
SchemaErrorAggregator = ApatheticSchema_Internal_SchemaErrorAggregator
60-
else:
61-
SchErrAggEntry = apathetic_schema.SchErrAggEntry
62-
SchemaErrorAggregator = apathetic_schema.SchemaErrorAggregator
57+
# Export type aliases and dataclasses
58+
# Types are imported from types module above
59+
# ValidationSummary comes from apathetic_schema class
6360
ValidationSummary = apathetic_schema.ValidationSummary
6461

6562

6663
__all__ = [
6764
"AGG_STRICT_WARN",
6865
"AGG_WARN",
6966
"DEFAULT_HINT_CUTOFF",
70-
"SchErrAggEntry",
71-
"SchemaErrorAggregator",
67+
"ApatheticSchema_SchErrAggEntry",
68+
"ApatheticSchema_SchemaErrorAggregator",
7269
"ValidationSummary",
7370
"apathetic_schema",
7471
"check_schema_conformance",

src/apathetic_schema/flush_schema_aggregators.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111

1212
if TYPE_CHECKING:
13-
from .types import ApatheticSchema_Internal_Types
13+
from .types import (
14+
ApatheticSchema_Internal_Types,
15+
ApatheticSchema_SchemaErrorAggregator,
16+
)
1417

1518

1619
class ApatheticSchema_Internal_FlushSchemaAggregators: # noqa: N801 # pyright: ignore[reportUnusedClass]
@@ -25,7 +28,7 @@ class ApatheticSchema_Internal_FlushSchemaAggregators: # noqa: N801 # pyright:
2528
def flush_schema_aggregators(
2629
*,
2730
summary: ApatheticSchema_Internal_Types.ValidationSummary,
28-
agg: ApatheticSchema_Internal_Types.SchemaErrorAggregator, # type: ignore[valid-type]
31+
agg: ApatheticSchema_SchemaErrorAggregator,
2932
) -> None:
3033
"""Flush aggregated schema validation messages to the summary.
3134
@@ -57,8 +60,8 @@ def _flush_one(
5760
)
5861
bucket.clear()
5962

60-
strict_bucket = agg.get(ApatheticSchema_Internal_Constants.AGG_STRICT_WARN, {}) # type: ignore[attr-defined]
61-
warn_bucket = agg.get(ApatheticSchema_Internal_Constants.AGG_WARN, {}) # type: ignore[attr-defined]
63+
strict_bucket = agg.get(ApatheticSchema_Internal_Constants.AGG_STRICT_WARN, {})
64+
warn_bucket = agg.get(ApatheticSchema_Internal_Constants.AGG_WARN, {})
6265

6366
if strict_bucket:
6467
summary.valid = False

src/apathetic_schema/types.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# --- TypedDict definitions ---------------------------------------------
1111

1212

13-
class ApatheticSchema_Internal_SchErrAggEntry(TypedDict): # noqa: N801
14-
"""Internal type for schema error aggregator entries."""
13+
class ApatheticSchema_SchErrAggEntry(TypedDict): # noqa: N801
14+
"""Type for schema error aggregator entries."""
1515

1616
msg: str
1717
contexts: list[str]
@@ -29,8 +29,8 @@ class ApatheticSchema_Internal_SchErrAggEntry(TypedDict): # noqa: N801
2929
# },
3030
# "warnings": { ... }
3131
# }
32-
ApatheticSchema_Internal_SchemaErrorAggregator: TypeAlias = dict[
33-
str, dict[str, dict[str, ApatheticSchema_Internal_SchErrAggEntry]]
32+
ApatheticSchema_SchemaErrorAggregator: TypeAlias = dict[
33+
str, dict[str, dict[str, ApatheticSchema_SchErrAggEntry]]
3434
]
3535

3636

@@ -42,16 +42,6 @@ class ApatheticSchema_Internal_Types: # noqa: N801 # pyright: ignore[reportUnu
4242
access to these types via the namespace class.
4343
"""
4444

45-
# --- TypedDict definitions ---------------------------------------------
46-
47-
# Reference to module-level TypedDict
48-
SchErrAggEntry = ApatheticSchema_Internal_SchErrAggEntry
49-
50-
# --- Type aliases -------------------------------------------------------
51-
52-
# Reference to module-level type alias
53-
SchemaErrorAggregator = ApatheticSchema_Internal_SchemaErrorAggregator
54-
5545
# --- Dataclasses --------------------------------------------------------
5646

5747
@dataclass
@@ -72,5 +62,6 @@ class ValidationSummary:
7262

7363
# Export types with ApatheticSchema_ prefix for external packages
7464
# (e.g., serger) that import directly from types module
75-
ApatheticSchema_SchemaErrorAggregator = ApatheticSchema_Internal_SchemaErrorAggregator
65+
# Note: ApatheticSchema_SchErrAggEntry and ApatheticSchema_SchemaErrorAggregator
66+
# are already defined above with the correct prefix
7667
ApatheticSchema_ValidationSummary = ApatheticSchema_Internal_Types.ValidationSummary

src/apathetic_schema/warn_keys_once.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .types import (
1313
ApatheticSchema_Internal_Types,
1414
ApatheticSchema_SchemaErrorAggregator,
15+
ApatheticSchema_SchErrAggEntry,
1516
)
1617

1718

@@ -37,7 +38,7 @@ def warn_keys_once(
3738
*,
3839
strict_config: bool,
3940
summary: ApatheticSchema_Internal_Types.ValidationSummary, # modified in-place
40-
agg: ApatheticSchema_Internal_Types.SchemaErrorAggregator | None, # type: ignore[valid-type]
41+
agg: ApatheticSchema_SchemaErrorAggregator | None,
4142
) -> tuple[bool, set[str]]:
4243
"""Warn once for known bad keys (e.g. dry-run, root-only).
4344
@@ -77,11 +78,11 @@ def warn_keys_once(
7778
)
7879

7980
bucket = cast_hint(
80-
dict[str, ApatheticSchema_Internal_Types.SchErrAggEntry], # type: ignore[valid-type]
81+
dict[str, ApatheticSchema_SchErrAggEntry],
8182
agg.setdefault(severity, {}),
8283
)
8384

84-
default_entry: ApatheticSchema_Internal_Types.SchErrAggEntry = { # type: ignore[valid-type]
85+
default_entry: ApatheticSchema_SchErrAggEntry = {
8586
"msg": msg,
8687
"contexts": [],
8788
}

tests/30_independant/test_flush_schema_aggregators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
def test_flush_schema_aggregators_flushes_strict_bucket() -> None:
1212
# --- setup ---
1313
summary = make_summary(strict=True)
14-
agg: amod_schema.SchemaErrorAggregator = cast(
15-
"amod_schema.SchemaErrorAggregator",
14+
agg: amod_schema.ApatheticSchema_SchemaErrorAggregator = cast(
15+
"amod_schema.ApatheticSchema_SchemaErrorAggregator",
1616
{
1717
amod_schema.AGG_STRICT_WARN: {
1818
"dry-run": {
@@ -44,8 +44,8 @@ def test_flush_schema_aggregators_flushes_strict_bucket() -> None:
4444
def test_flush_schema_aggregators_flushes_warning_bucket() -> None:
4545
# --- setup ---
4646
summary = make_summary(strict=False)
47-
agg: amod_schema.SchemaErrorAggregator = cast(
48-
"amod_schema.SchemaErrorAggregator",
47+
agg: amod_schema.ApatheticSchema_SchemaErrorAggregator = cast(
48+
"amod_schema.ApatheticSchema_SchemaErrorAggregator",
4949
{
5050
amod_schema.AGG_WARN: {
5151
"root-only": {
@@ -73,8 +73,8 @@ def test_flush_schema_aggregators_flushes_warning_bucket() -> None:
7373
def test_flush_schema_aggregators_cleans_context_prefixes() -> None:
7474
# --- setup ---
7575
summary = make_summary(strict=True)
76-
agg: amod_schema.SchemaErrorAggregator = cast(
77-
"amod_schema.SchemaErrorAggregator",
76+
agg: amod_schema.ApatheticSchema_SchemaErrorAggregator = cast(
77+
"amod_schema.ApatheticSchema_SchemaErrorAggregator",
7878
{
7979
amod_schema.AGG_STRICT_WARN: {
8080
"noop": {

tests/30_independant/test_warn_keys_once.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_warn_keys_once_with_aggregator_non_strict() -> None:
4444
"""When agg is provided and strict=False, should aggregate warnings."""
4545
# --- setup ---
4646
summary = make_summary(strict=False)
47-
agg: amod_schema.SchemaErrorAggregator = {}
47+
agg: amod_schema.ApatheticSchema_SchemaErrorAggregator = {}
4848
cfg = {"dry_run": True, "valid": "value"}
4949
bad_keys = {"dry_run"}
5050

@@ -65,7 +65,10 @@ def test_warn_keys_once_with_aggregator_non_strict() -> None:
6565
assert found == {"dry_run"}
6666
assert "warnings" in agg
6767
assert "dry-run" in agg["warnings"]
68-
entry = cast("amod_schema.SchErrAggEntry", agg["warnings"]["dry-run"])
68+
entry = cast(
69+
"amod_schema.ApatheticSchema_SchErrAggEntry",
70+
agg["warnings"]["dry-run"],
71+
)
6972
expected_msg = "The 'dry-run' key is deprecated {ctx}"
7073
assert entry["msg"] == expected_msg
7174
assert "in top-level configuration" in entry["contexts"]
@@ -78,7 +81,7 @@ def test_warn_keys_once_with_aggregator_strict() -> None:
7881
"""When agg is provided and strict=True, should aggregate strict warnings."""
7982
# --- setup ---
8083
summary = make_summary(strict=True)
81-
agg: amod_schema.SchemaErrorAggregator = {}
84+
agg: amod_schema.ApatheticSchema_SchemaErrorAggregator = {}
8285
cfg = {"dry_run": True}
8386
bad_keys = {"dry_run"}
8487

@@ -99,7 +102,10 @@ def test_warn_keys_once_with_aggregator_strict() -> None:
99102
assert found == {"dry_run"}
100103
assert "strict_warnings" in agg
101104
assert "dry-run" in agg["strict_warnings"]
102-
entry = cast("amod_schema.SchErrAggEntry", agg["strict_warnings"]["dry-run"])
105+
entry = cast(
106+
"amod_schema.ApatheticSchema_SchErrAggEntry",
107+
agg["strict_warnings"]["dry-run"],
108+
)
103109
expected_msg = "Deprecated key {keys} {ctx}"
104110
assert entry["msg"] == expected_msg
105111
assert "in config" in entry["contexts"]
@@ -109,7 +115,7 @@ def test_warn_keys_once_with_aggregator_multiple_contexts() -> None:
109115
"""Aggregator should collect multiple contexts for the same tag."""
110116
# --- setup ---
111117
summary = make_summary()
112-
agg: amod_schema.SchemaErrorAggregator = {}
118+
agg: amod_schema.ApatheticSchema_SchemaErrorAggregator = {}
113119
bad_keys = {"dry_run"}
114120

115121
# --- execute ---
@@ -138,7 +144,10 @@ def test_warn_keys_once_with_aggregator_multiple_contexts() -> None:
138144
)
139145

140146
# --- verify ---
141-
entry = cast("amod_schema.SchErrAggEntry", agg["warnings"]["dry-run"])
147+
entry = cast(
148+
"amod_schema.ApatheticSchema_SchErrAggEntry",
149+
agg["warnings"]["dry-run"],
150+
)
142151
expected_context_count = 2
143152
assert len(entry["contexts"]) == expected_context_count
144153
assert "context1" in entry["contexts"]

0 commit comments

Comments
 (0)