Repository navigation
292 remove objbase - #314
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 308-remove-name #314 +/- ##
====================================================
+ Coverage 83.44% 94.11% +10.66%
====================================================
Files 69 52 -17
Lines 5177 4128 -1049
====================================================
- Hits 4320 3885 -435
+ Misses 857 243 -614
Flags with carried forward coverage won't be shown. Click here to find out more.
|
forwarding serialization inclusions
|
Replacement of An override of When a parent object is serialized,
So moving the list-specific logic means the items are written in both cases. It also helps EasyList when duplicating what NewBase.to_dict() already does. Also: The old override was to_dict(self) with no skip parameter. NewBase.copy calls self.to_dict(skip=['unique_name']), which would have raised a TypeError on an EasyList. The original ignored skip and still called item.to_dict() for each item. The current version passes skip on to each item and gives each item its own copy (list(skip)), because NewBase.to_dict() appends to the list it is given. |
Our serialization contract is This is the correct approach, not removing |
damskii9992
left a comment
There was a problem hiding this comment.
I already wrote my main comment about the to_dict method, but that needs changing. Otherwise only some minor stuff.
| if hasattr(obj, '_kwargs'): | ||
| # type: ignore | ||
| option = getattr(obj, '_kwargs') | ||
| if hasattr(option, c): | ||
| v = getattr(option, c) | ||
| delattr(option, c) | ||
| d.update(runner(v)) # pylint: disable=E1101 | ||
| err = False |
There was a problem hiding this comment.
I'm totally for removing this (and the above) branch of code, which tries to get the attribute from a public and internal "kwargs" method, but why remove it here? What is the reason you're removing it and why only the internal one?
Nope. This hook is a post-processing callback, not an entry point, so swapping the names fails in three ways:
On the other hand... "Our contract is to_dict/from_dict" is a good design idea. Maybe we should make the elif hasattr(obj, 'to_dict') and obj.__class__.__module__.startswith('easy'):
return obj.to_dict(skip=list(skip))this way nested Parameter will keep its dependency fields |
|
Meh, there's still an issue with from easyscience import Parameter
from easyscience.base_classes import EasyList
# A list with no display_name, with an item that has display_name.
el = EasyList(Parameter(1.0, display_name='c0'))
d = el.to_dict()
print('display_name' in d['data'][0]) # False (expected True)
# now go to_dict->from_dict and the name is gone, it gets the default
el2 = EasyList.from_dict(d)
print(el2[0].display_name) # Parameter_1 (expected 'c0')
# Same list, but give the list itself a display_name: the item now keeps its name.
el3 = EasyList(Parameter(1.0, display_name='c0'), display_name='coeffs')
print('display_name' in el3.to_dict()['data'][0]) # True |
Well, you introduced this one. The |
Yes, I think we should think of serialization this way: If an object is our own object and it has a This way we can control how our own objects gets serialized by overwriting |
Remove _REDIRECT; serializer relies on _arg_spec only
| skip.append('unique_name') | ||
| if self._display_name is None: | ||
| skip.append('display_name') | ||
| skip = list(skip) if skip else [] |
There was a problem hiding this comment.
You're removing crucial serialization functionality here, check out my pr #325 which should be doing what we want the NewBase to_dict method to do.
There was a problem hiding this comment.
Should we move SerializerBase to our base_classes module now that it is the only class in this module?
There was a problem hiding this comment.
will do that on #313 after merge, so it's easier
Removed/replaced the legacy
ObjBaseandCollectionBaseclasses with the newEasyListandModelBaseclasses.Removed references to legacy APIs from documentation, configuration, and import statements.
Removed Hugger and Property from global_object\hugger
Removed Models/polynomial.py and associated tests. This required adding a stub model in tests/helpers/easy_test_models.py
Changed
EasyList.to_dicttoEasyList._convert_to_dict, because an override of to_dict only runs when someone calls easy_list.to_dict() directly. It never runs when the list is nested inside another object.