You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Schemaview: add helper to return extra_slots of a class's ancestors #4145
A class's own extra_slots is not inherited in the metamodel, but its inherited by generated OO code. A Java subclass inherits its parent's handling of extra data. A Pydantic subclass inherits its parent's model_config and pydantic_extra.
So generator has to read ancestors' extra_slots to decide what each generated class must state for itself. At least two generators repeat the pattern today:
JavaGenerator.needs_extra_slots skips the extra-slots code when an ancestor allows extra data.
PydanticGenerator._get_extra_for_class (#3630) writes a class's own extra_slots setting when it differs from what the class would inherit. For example, if the parent accepts extra values of one type, an allowed: true subclass declares it accepts extra values of any type. If the parent allows extra data, a subclass with no extra_slots will forbid extra data.
A SchemaView method could do the walk once for both, for example:
def class_ancestors_extra_slots(
self, class_name: CLASS_NAME, mixins: bool = True
) -> dict[CLASS_NAME, ExtraSlotsExpression]:
"""The extra_slots of each ancestor that sets one, in class_ancestors order."""
Each generator would keep its own rule for what to emit. Materializing extra_slots in induced_class would not help, because the metamodel does not pass the value down.
Activity