New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trait inheritance doesn't work as expected for List traits #1630
Comments
It seems as though we always specify a Lines 593 to 599 in d1949c6
That mostly works, because |
…value_type (#1631) This is a two-part fix for #1629: - Part 1: fix `ctraits.c` to validate the input to `set_default_value` in the case where the given default value type is `DefaultValue.callable_and_args`. This fixes the segfault reported in #1629, replacing it with a more scrutable Python-level exception. - Part 2: in the `TraitType.clone` base class implementation, when we set a default value, also set the default value type to be consistent with that default value. This still leaves open the possibility for `TraitType` subclasses to do their own thing in their `clone` methods (and in particular, the `List`, `Dict` and `Set` trait types will probably want to take advantage of that - see #1630).
A note that enthought/enable#945 is a different twist on the same root problem. |
Another related failure for
This is getting at the |
My suspicion here is that the intent of |
So after some digging and experimentation, in
Additionally traits which use
For
|
I think we shouldn't make any changes for For
For the general solution, I'd like to avoid doing any kind of guesswork in the
Yes, I think this would be the right thing, together with examples / guidance about how to extend |
I've opened a draft PR starting with a bunch of tests that I think should pass (but which currently don't, for various reasons), and which roughly correspond to the above without breaking backwards compatibility too much. In particular, the tests only expect exceptions when you try to clone a trait with default value type "disallow". Probably a good first step is to see if these match expectations. |
…value_type (#1631) This is a two-part fix for #1629: - Part 1: fix `ctraits.c` to validate the input to `set_default_value` in the case where the given default value type is `DefaultValue.callable_and_args`. This fixes the segfault reported in #1629, replacing it with a more scrutable Python-level exception. - Part 2: in the `TraitType.clone` base class implementation, when we set a default value, also set the default value type to be consistent with that default value. This still leaves open the possibility for `TraitType` subclasses to do their own thing in their `clone` methods (and in particular, the `List`, `Dict` and `Set` trait types will probably want to take advantage of that - see #1630). (cherry picked from commit dc59b5c)
This PR works towards a fix of #1630 and related issues. The starting point is a set of regression tests that identify the behaviour which doesn't seem correct and test for the expected behaviour. This then adds changes to TraitTypes.clone that fix a number of the observed issues. We then remove the default value wrangling in HasTraits as it should no longer be needed. I think at this point everything is in a better state than it was: we have less unexpected behaviour. There may be subsequent things which might be advisable, such as raising warnings about future deprecation of certain behaviours, adding clone methods to particular trait types, etc. Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
This PR works towards a fix of #1630 and related issues. The starting point is a set of regression tests that identify the behaviour which doesn't seem correct and test for the expected behaviour. This then adds changes to TraitTypes.clone that fix a number of the observed issues. We then remove the default value wrangling in HasTraits as it should no longer be needed. I think at this point everything is in a better state than it was: we have less unexpected behaviour. There may be subsequent things which might be advisable, such as raising warnings about future deprecation of certain behaviours, adding clone methods to particular trait types, etc. Co-authored-by: Mark Dickinson <mdickinson@enthought.com> (cherry picked from commit 7ecd065)
Traits allows specifying a default value for a trait defined in a superclass. But this doesn't work in the expected way for
List
,Dict
andSet
traits. For example:After instantiating
B
withb = B()
, we get the expected default, butb.foo
no longer behaves like a validated list:Worse, the default is shared between all instances of
B
, which almost certainly isn't what's intended.This doesn't appear to be a particularly new problem - it goes back at least to Traits 5.2.
The text was updated successfully, but these errors were encountered: