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
Default value introduced in subclass does not propagate to constructor #467
This line drops the parent properties from the constructor by name; however, I think it's valid for subclasses to add/change the default for a parent property. Since we're dropping the subclass properties, the changed default does not make it to the constructor. Self args should probably be kept (and override the parent) if they have a different default.
When I was refactoring a class (that had defaults in one of its properties) to be now a child class of a some template class that I want to use that also has this property. Suddenly my defaults were not working anymore!
I should note that my parent template class does not set a default, nor does it have custom construction (which was flagged as a potential issue in #473 ). It is the simplest parent class you can imagine, yet it triggered this bug which was quite surprising with such simple class definitions that I had.
In my opinion, this is the most annoying issue with S7 at the moment. Would be good to resolve the concerns with the PR. I'm not sure I fully understand them.
@t-kalinowski In the PR you mentioned that it is tricky if the parent has a custom constructor. Because then the default value is implicitly different.
There’s one drawback of custom constructors that you should be aware of: any subclass will also require a custom constructor.
And if a class has a custom constructor the user should automatically be aware defaults specified in parameter are ignored as the default argument of the constructor takes priority. Meaning the users needs to be explicit anyway with the defaults for its child class with the constructor. So there is no issue here.
(Side note, maybe S7 could issue a warning if the user does provide a custom constructor and has default priorities set. Or elaborate more on the document of default in ?new_property)
However there is still the issue that the default cannot be overwritten by a child class even if the parent class does not have a default constructor.
Activity
Allow child classes to change default value of parent properties
ltuijnder commentedon May 2, 2025
Hi I too stumbled upon this issue.
When I was refactoring a class (that had defaults in one of its properties) to be now a child class of a some template class that I want to use that also has this property. Suddenly my defaults were not working anymore!
I should note that my parent template class does not set a default, nor does it have custom construction (which was flagged as a potential issue in #473 ). It is the simplest parent class you can imagine, yet it triggered this bug which was quite surprising with such simple class definitions that I had.
lawremi commentedon May 3, 2025
In my opinion, this is the most annoying issue with S7 at the moment. Would be good to resolve the concerns with the PR. I'm not sure I fully understand them.
ltuijnder commentedon May 5, 2025
@t-kalinowski In the PR you mentioned that it is tricky if the parent has a custom constructor. Because then the default value is implicitly different.
But in my mind there is no issue. In case the parent has a custom constructor. it was already documented that the child should also define a custom constructor: https://rconsortium.github.io/S7/articles/classes-objects.html#constructors
And if a class has a custom constructor the user should automatically be aware defaults specified in parameter are ignored as the default argument of the constructor takes priority. Meaning the users needs to be explicit anyway with the defaults for its child class with the constructor. So there is no issue here.
(Side note, maybe S7 could issue a warning if the user does provide a custom constructor and has default priorities set. Or elaborate more on the document of
defaultin?new_property)However there is still the issue that the default cannot be overwritten by a child class even if the parent class does not have a default constructor.
hadley commentedon May 21, 2026
Small example:
Improve construction of subclasses (RConsortium#694)