Open ipcoder opened 4 years ago
Can you give me an example of how that would be used so I understand what you want to accomplish with it?
First I would like to stress that may remark/suggestion is about widening the meaning - not changing the code. The docs assume its only type casting can be used, but actually any function can be provided, "normalizing" the data in any required sense, for example:
Box(..., box_recast={'name': lambda x: x.title(), ...})
So, technically, one can use that already now, right? Its just that documentation seems to imply that only type casting can be used,
I have updated to 5.0.1 and this extended behavior is not working anymore.
It seems now there is an explicit assumption casting is to a class (if issubclass(...
in box.py:407
):
def __recast(self, item, value):
if self._box_config["box_recast"] and item in self._box_config["box_recast"]:
try:
if issubclass(self._box_config["box_recast"][item], (Box, box.BoxList)):
Is that your design decision to forbid extended interpretation of recasting as discussed above?
That was actually added to fix another issue being experienced, and of course didn't have the above test case to see how that would affect that ability.
I will look into if it is possible to have it work as needed as it currently stands, as well as the above code, or if they would need to be separate things.
Don't you think we can expand the meaning of the
box_recast
and consider it as a more generic mapping operation, that iswhere the
callable
could be a type or any other callable object returning a value? It seems nothing prevents such interpretation already, right?Thanks