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
The value of a Parameter attribute - like default, doc, etc. - is inherited in a hierarchy of Parameterized classes. In practice, the inheritance only applies when the default attribute value is None.
In the example below, B is a subclass of A and the user intent seems to be to override the definitions of p1 and p2, from String and String to Action to Number, respectively. The result of that operation is that:
Because the default value of the default attribute of Action is None, B.p1.param.default will inherit from A.p1.param.default which is '1'. The value of p1 is then set based on that new default, leading to b.p1 == '1'. This is an invalid value for a Number.
Because the default value of the default attribute of Action is not None but 0.0, it is used directly to set B.p1.param.default, leading to b.p1 == 0.0.
The focus of this issue is on the default attribute as it can be used to set the actual Parameter value, if the user does not provide a default when instantiating the class. But this issue is more general, the Parameters of a subclass can inherit other invalid attributes without any error/warning.
This discussion is linked to the proposal of enforcing an "is-a" relationship (#97 (comment)) between Parameters in a class hierarchy.
A pragmatic approach to this issue might be to run the Parameter validation code (Parameter._validate) after the whole inheritance procedure is executed, and emit a warning if that fails. As to avoid the issue above with p1, the author of B should define a default value for the overriding p1.
The text was updated successfully, but these errors were encountered:
@jbednar this is not completely fixed. #812 only added validation of default when a Parameter is not a subclass of it parent Parameter. So there's no validation in that kind of more common case:
The value of a Parameter attribute - like
default
,doc
, etc. - is inherited in a hierarchy of Parameterized classes. In practice, the inheritance only applies when the default attribute value isNone
.In the example below,
B
is a subclass ofA
and the user intent seems to be to override the definitions ofp1
andp2
, fromString
andString
toAction
toNumber
, respectively. The result of that operation is that:default
attribute ofAction
isNone
,B.p1.param.default
will inherit fromA.p1.param.default
which is'1'
. The value ofp1
is then set based on that newdefault
, leading tob.p1 == '1'
. This is an invalid value for aNumber
.default
attribute ofAction
is notNone
but0.0
, it is used directly to setB.p1.param.default
, leading tob.p1 == 0.0
.The focus of this issue is on the
default
attribute as it can be used to set the actual Parameter value, if the user does not provide a default when instantiating the class. But this issue is more general, the Parameters of a subclass can inherit other invalid attributes without any error/warning.This discussion is linked to the proposal of enforcing an "is-a" relationship (#97 (comment)) between Parameters in a class hierarchy.
A pragmatic approach to this issue might be to run the Parameter validation code (
Parameter._validate
) after the whole inheritance procedure is executed, and emit a warning if that fails. As to avoid the issue above withp1
, the author ofB
should define a default value for the overridingp1
.The text was updated successfully, but these errors were encountered: