Commit 86cdb2f
authored
Fix that clone_traits doesn't respect dynamic traits (#1846)
Closes #1845
This PR fixes `clone_traits` (and `copy_traits`) to respect dynamic
traits.
Previously, the `HasTraits.copy_traits` method used a mixture of trait
information from `self` (the object being copied _to_) and `other` (the
object being copied _from_) to determine how to behave. Since the actual
copying was enclosed in a large `try / except` block, any errors arising
just resulted in the trait value not being copied.
In particular, when cloning a `HasTraits` object with dynamically-added
traits:
- the set of traits to copy was first determined by inspecting the
object, and included those dynamically-added traits
- then, in `copy_traits`, we inspect the cloned object that we're
copying _to_, which doesn't have the dynamically-added traits, and as a
result we fail to copy those trait values.
This PR updates the logic to only use the trait information from `other`
when deciding what / how to copy, instead of using a mixture of sources.
As a result, `clone_traits` should behave as expected on objects with
dynamically-added traits.
We have a large corpus of existing Traits code, and like all changes to
Traits this change risks unintended consequences and surprise breakages
of existing code that's inadvertently relying on the existing behaviour.
While I think it's the right change to make, I'd advocate not
backporting this change to any bugfix branch, and highlighting the
change prominently in release notes.1 parent ce0af93 commit 86cdb2f
2 files changed
+22
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1554 | 1554 | | |
1555 | 1555 | | |
1556 | 1556 | | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
1560 | 1560 | | |
1561 | 1561 | | |
1562 | 1562 | | |
| |||
1572 | 1572 | | |
1573 | 1573 | | |
1574 | 1574 | | |
1575 | | - | |
| 1575 | + | |
1576 | 1576 | | |
1577 | | - | |
| 1577 | + | |
1578 | 1578 | | |
1579 | 1579 | | |
1580 | 1580 | | |
| |||
1585 | 1585 | | |
1586 | 1586 | | |
1587 | 1587 | | |
1588 | | - | |
| 1588 | + | |
1589 | 1589 | | |
1590 | 1590 | | |
1591 | 1591 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
0 commit comments