Commit f780c47
Use dir() instead of vars() in
Previously, we used `vars()` to iterate over all attributes of an object
when updating it from another object (`Referable.update_from()`).
However, `vars()` only retrieves the instance's `__dict__`, e.g. the
object's attributes, but does not include properties. As a result, when
you use `vars(other)`, you get the `_id_short` attribute instead of the
`id_short` property.
This made it impossible to utilize custom setter methods we developed
for certain cases, e.g. when properties should be immutable.
This now adapts the `Referable.update_from()` method to utilize `dir()`
instead, which iterates over all attributes and properties of the
object. We skip callables and private attributes. We use `setattr()` to
set attributes and properties, so that the correct setter methods will
be used.
Furthermore, we now raise an error if an immutable property changed
between the two versions of the object.
Fixes #215
---------
Co-authored-by: Sercan Sahin <[email protected]>Referable.update_from() (#338)1 parent 1d38288 commit f780c47
1 file changed
+23
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
802 | 802 | | |
803 | 803 | | |
804 | 804 | | |
805 | | - | |
| 805 | + | |
806 | 806 | | |
807 | 807 | | |
808 | 808 | | |
| |||
811 | 811 | | |
812 | 812 | | |
813 | 813 | | |
814 | | - | |
815 | | - | |
816 | | - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
817 | 817 | | |
818 | | - | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
819 | 829 | | |
820 | | - | |
| 830 | + | |
821 | 831 | | |
822 | | - | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
823 | 839 | | |
824 | 840 | | |
825 | 841 | | |
| |||
0 commit comments