Skip to content

Allow derived structs to override base fields with subtypes#681

Merged
AdamGlustein merged 3 commits intomainfrom
derived-struct-field-overrides-2
Mar 16, 2026
Merged

Allow derived structs to override base fields with subtypes#681
AdamGlustein merged 3 commits intomainfrom
derived-struct-field-overrides-2

Conversation

@AdamGlustein
Copy link
Collaborator

@AdamGlustein AdamGlustein commented Feb 23, 2026

Closes #517 , allows for derived struct types to specialize fields iff those fields are Python objects or csp.Structs.

For example,

class A(csp.Struct):
    field1: BaseObject
    field2: InnerBaseStruct

class B(A):
    field1: DerivedObject
    field2: InnerDerivedStruct

is allowed, but

class A(csp.Struct):
    field1: int

class B(A):
    field1: float

or

class A(csp.Struct):
    field1: DerivedObject

class B(A):
    field1: BaseObject

are not. Note that a lot of the changes in Struct.cpp is just a reordering of when we create the set/none masks; before we did this before adding base class fields, now we do it after.

@AdamGlustein AdamGlustein added the type: enhancement Issues and PRs related to improvements to existing features label Feb 23, 2026
Signed-off-by: Adam Glustein <adam.glustein@point72.com>
@AdamGlustein AdamGlustein force-pushed the derived-struct-field-overrides-2 branch from 9d51c23 to f718205 Compare February 24, 2026 14:35
p72dennisxu
p72dennisxu previously approved these changes Feb 24, 2026
…onstruction and only then adding derived fields

Signed-off-by: Adam Glustein <adam.glustein@point72.com>
@AdamGlustein AdamGlustein force-pushed the derived-struct-field-overrides-2 branch from e5e35bf to 170bb72 Compare March 13, 2026 16:00
…rocessing, simplifies the logic and indexing

Signed-off-by: Adam Glustein <adam.glustein@point72.com>
@AdamGlustein AdamGlustein force-pushed the derived-struct-field-overrides-2 branch from 8311bd3 to eaf9f4b Compare March 16, 2026 16:43
@AdamGlustein AdamGlustein merged commit 82b6b2f into main Mar 16, 2026
25 checks passed
@AdamGlustein AdamGlustein deleted the derived-struct-field-overrides-2 branch March 16, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Issues and PRs related to improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow derived csp.Struct classes to override base class types if new types are more specialized

3 participants