[core] Reference the attribute's instance type in its description #2493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new property called
instanceType
in the attribute description classes that contains the class of the corresponding attribute object.This property is then used to instantiate directly attribute objects, rather than performing tests on the type of the description class to determine which constructor to use.
This solves an issue where any description that would inherit from an existing one would lead to instantiating an attribute of the parent class, e.g. having a description class inheriting
ChoiceParam
would always lead to aChoiceParam
attribute being created, even if a dedicated attribute class corresponding to that description existed.To set
instanceType
in a description class, thegetInstanceType
method can be overriden. By default,instanceType
will always be set toAttribute
.Below is an example of custom description and attribute classes that inherit
ChoiceParam
, and a node using this new attribute: