mahmoud / boltons

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.
https://boltons.readthedocs.org
Other
6.54k stars 353 forks source link

research should accept remap args #368

Closed majidaldo closed 4 months ago

majidaldo commented 5 months ago

https://github.com/mahmoud/boltons/blob/6a363e6c4837a2cca606eba5903ea6f4ae83d745/boltons/iterutils.py#L1355

for the case where you have you custom enter.

mahmoud commented 5 months ago

Interesting, sure, I guess I could see a custom enter if you were trying to traverse iterables which default_enter doesn't support.

Just looking at this, I think I would change research to use visit instead of enter and then allow a custom enter to be passed. But I don't think there's much value to a custom visit or exit, can you think of any?

majidaldo commented 5 months ago

Interesting, sure, I guess I could see a custom enter if you were trying to traverse iterables which default_enter doesn't support.

Just looking at this, I think I would change research to use visit instead of enter and then allow a custom enter to be passed. But I don't think there's much value to a custom visit or exit, can you think of any?

Didn't understand "and then allow a custom enter to be passed". The case that I had in mind, is when the object at the root is 'custom'... you need a way to compose/decompose.

 from types import SimpleNamespace as NS
 NS(
        a='a',
        b='b',
            c=NS(aa='aa') )
mahmoud commented 4 months ago

@majidaldo just pushed a PR (#372) that I think is closer to what you might have expected. check out the test to see it in action with SimpleNamespace.