Skip to content
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

Box recast meaning #153

Open
ipcoder opened this issue May 18, 2020 · 4 comments
Open

Box recast meaning #153

ipcoder opened this issue May 18, 2020 · 4 comments

Comments

@ipcoder
Copy link

ipcoder commented May 18, 2020

Don't you think we can expand the meaning of the box_recast and consider it as a more generic mapping operation, that is

Box(..., box_recast={'item': callable, ...})

where the callable could be a type or any other callable object returning a value?
It seems nothing prevents such interpretation already, right?

Thanks

@cdgriffith
Copy link
Owner

Can you give me an example of how that would be used so I understand what you want to accomplish with it?

@ipcoder
Copy link
Author

ipcoder commented Jul 3, 2020

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,

@ipcoder
Copy link
Author

ipcoder commented Jul 15, 2020

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?

@cdgriffith
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants