@@ -39,7 +39,7 @@ class MalformedUnionError(TypeParameterError):
3939 pass
4040
4141
42- class DeprecatedDependencyError (TypeParameterError ):
42+ class DeprecatedDependencyError (AggregationError ):
4343 pass
4444
4545
@@ -81,10 +81,8 @@ def __init__( # pylint: disable=too-many-arguments
8181 # Name check
8282 if not self ._name :
8383 raise InvalidNameError ("Composite type name cannot be empty" )
84-
8584 if self .NAME_COMPONENT_SEPARATOR not in self ._name :
8685 raise InvalidNameError ("Root namespace is not specified" )
87-
8886 if len (self ._name ) > self .MAX_NAME_LENGTH :
8987 # TODO
9088 # Notice that per the Specification, service request/response types are unnamed,
@@ -95,7 +93,6 @@ def __init__( # pylint: disable=too-many-arguments
9593 raise InvalidNameError (
9694 "Name is too long: %r is longer than %d characters" % (self ._name , self .MAX_NAME_LENGTH )
9795 )
98-
9996 for component in self ._name .split (self .NAME_COMPONENT_SEPARATOR ):
10097 check_name (component )
10198
@@ -105,7 +102,6 @@ def __init__( # pylint: disable=too-many-arguments
105102 and (0 <= self ._version .minor <= self .MAX_VERSION_NUMBER )
106103 and ((self ._version .major + self ._version .minor ) > 0 )
107104 )
108-
109105 if not version_valid :
110106 raise InvalidVersionError ("Invalid version numbers: %s.%s" % (self ._version .major , self ._version .minor ))
111107
@@ -132,14 +128,14 @@ def __init__( # pylint: disable=too-many-arguments
132128 # A deprecated type can be dependent on anything.
133129 if not self .deprecated :
134130 for a in self ._attributes :
135- t = a .data_type
136- if isinstance ( t , CompositeType ):
137- if t . deprecated :
138- raise DeprecatedDependencyError (
139- "A type cannot depend on deprecated types unless it is also deprecated."
140- )
141-
142- # Aggregation check. For example, types like utf8 and byte cannot be used outside of arrays .
131+ if a .data_type . deprecated :
132+ raise DeprecatedDependencyError (
133+ "A type cannot depend on deprecated types unless it is also deprecated."
134+ )
135+
136+ # Aggregation check. For example:
137+ # - Types like utf8 and byte cannot be used outside of arrays.
138+ # - A non-deprecated type cannot depend on a deprecated type .
143139 for a in self ._attributes :
144140 if not a .data_type .is_valid_aggregate (self ):
145141 raise AggregationError ("Type of %r is not a valid field type for %s" % (str (a ), self ))
@@ -201,11 +197,15 @@ def bit_length_set(self) -> BitLengthSet:
201197 raise NotImplementedError
202198
203199 def is_valid_aggregate (self , aggregate : SerializableType ) -> bool :
200+ if self .deprecated : # Deprecation consistency check: non-deprecated cannot depend on a deprecated type.
201+ if isinstance (aggregate , CompositeType ) and not aggregate .deprecated :
202+ return False
203+
204204 return True
205205
206206 @property
207207 def deprecated (self ) -> bool :
208- """Whether the definition is marked ``@deprecated``."""
208+ """True if the definition is marked ``@deprecated``."""
209209 return self ._deprecated
210210
211211 @property
@@ -615,6 +615,9 @@ def iterate_fields_with_offsets(
615615 base_offset = base_offset + self .delimiter_header_type .bit_length_set
616616 return self .inner_type .iterate_fields_with_offsets (base_offset )
617617
618+ def is_valid_aggregate (self , aggregate : SerializableType ) -> bool :
619+ return self .inner_type .is_valid_aggregate (aggregate )
620+
618621 def __repr__ (self ) -> str :
619622 return "%s(inner=%r, extent=%r)" % (self .__class__ .__name__ , self .inner_type , self .extent )
620623
0 commit comments