Skip to content

Commit a963f8c

Browse files
Remove the aggregation check from the public API
1 parent c68c677 commit a963f8c

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

pydsdl/_serializable/_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def __init__(self, element_type: SerializableType, capacity: int):
2727
def deprecated(self) -> bool:
2828
return self.element_type.deprecated
2929

30-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
31-
af = self.element_type.check_aggregation(self)
30+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
31+
af = self.element_type._check_aggregation(self) # pylint: disable=protected-access
3232
if af is not None:
3333
return AggregationFailure(self, aggregate, "Element type of %r is not valid: %s" % (str(self), af.message))
34-
return super().check_aggregation(aggregate)
34+
return super()._check_aggregation(aggregate)
3535

3636
@property
3737
def element_type(self) -> SerializableType:

pydsdl/_serializable/_composite.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__( # pylint: disable=too-many-arguments
128128
# - Types like utf8 and byte cannot be used outside of arrays.
129129
# - A non-deprecated type cannot depend on a deprecated type.
130130
for a in self._attributes:
131-
af = a.data_type.check_aggregation(self)
131+
af = a.data_type._check_aggregation(self)
132132
if af is not None:
133133
raise AggregationError("Type of %r is not a valid field type for %s: %s" % (str(a), self, af.message))
134134

@@ -188,8 +188,8 @@ def bit_length_set(self) -> BitLengthSet:
188188
"""
189189
raise NotImplementedError
190190

191-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
192-
return super().check_aggregation(aggregate)
191+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
192+
return super()._check_aggregation(aggregate)
193193

194194
@property
195195
def deprecated(self) -> bool:
@@ -603,11 +603,11 @@ def iterate_fields_with_offsets(
603603
base_offset = base_offset + self.delimiter_header_type.bit_length_set
604604
return self.inner_type.iterate_fields_with_offsets(base_offset)
605605

606-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
607-
af = self.inner_type.check_aggregation(aggregate)
606+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
607+
af = self.inner_type._check_aggregation(aggregate) # pylint: disable=protected-access
608608
if af is not None:
609609
return af
610-
return super().check_aggregation(aggregate)
610+
return super()._check_aggregation(aggregate)
611611

612612
def __repr__(self) -> str:
613613
return "%s(inner=%r, extent=%r)" % (self.__class__.__name__, self.inner_type, self.extent)

pydsdl/_serializable/_primitive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def deprecated(self) -> bool:
5656
"""Primitive types cannot be deprecated."""
5757
return False
5858

59-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
60-
return super().check_aggregation(aggregate)
59+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
60+
return super()._check_aggregation(aggregate)
6161

6262
@property
6363
def bit_length(self) -> int:
@@ -178,12 +178,12 @@ class ByteType(UnsignedIntegerType):
178178
def __init__(self) -> None:
179179
super().__init__(bit_length=PrimitiveType.BITS_IN_BYTE, cast_mode=PrimitiveType.CastMode.TRUNCATED)
180180

181-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
181+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
182182
from ._array import ArrayType
183183

184184
if not isinstance(aggregate, ArrayType):
185185
return AggregationFailure(self, aggregate, "The byte type can only be used as an array element type")
186-
return super().check_aggregation(aggregate)
186+
return super()._check_aggregation(aggregate)
187187

188188
def __str__(self) -> str:
189189
return "byte"
@@ -197,14 +197,14 @@ class UTF8Type(UnsignedIntegerType):
197197
def __init__(self) -> None:
198198
super().__init__(bit_length=8, cast_mode=PrimitiveType.CastMode.TRUNCATED)
199199

200-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
200+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
201201
from ._array import VariableLengthArrayType
202202

203203
if not isinstance(aggregate, VariableLengthArrayType):
204204
return AggregationFailure(
205205
self, aggregate, "The utf8 type can only be used as a variable-length array element type"
206206
)
207-
return super().check_aggregation(aggregate)
207+
return super()._check_aggregation(aggregate)
208208

209209
def __str__(self) -> str:
210210
return "utf8"

pydsdl/_serializable/_serializable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TypeParameterError(_error.InvalidDefinitionError):
2222
],
2323
)
2424
"""
25-
This is returned by :meth:`SerializableType.check_aggregation()` to indicate the reason of the failure.
25+
This is returned by :meth:`SerializableType._check_aggregation()` to indicate the reason of the failure.
2626
Eventually this will need to be replaced with a dataclass (sadly no dataclasses in Python 3.6).
2727
"""
2828

@@ -80,7 +80,7 @@ def deprecated(self) -> bool:
8080
"""
8181
raise NotImplementedError
8282

83-
def check_aggregation(self, aggregate: "SerializableType") -> Optional[AggregationFailure]:
83+
def _check_aggregation(self, aggregate: "SerializableType") -> Optional[AggregationFailure]:
8484
"""
8585
Returns None iff the argument is a suitable aggregate type for this element type;
8686
otherwise, returns an instance of :class:`AggregationFailure` describing the reason of the failure.

pydsdl/_serializable/_void.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def deprecated(self) -> bool:
3030
"""Void types cannot be deprecated."""
3131
return False
3232

33-
def check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
33+
def _check_aggregation(self, aggregate: "SerializableType") -> typing.Optional[AggregationFailure]:
3434
from ._composite import StructureType, CompositeType
3535

3636
if not isinstance(aggregate, CompositeType) or not isinstance(aggregate.inner_type, StructureType):
3737
return AggregationFailure(self, aggregate, "Void types can only be aggregated into structures")
38-
return super().check_aggregation(aggregate)
38+
return super()._check_aggregation(aggregate)
3939

4040
@property
4141
def bit_length(self) -> int:

0 commit comments

Comments
 (0)