ingolemo / python-lenses

A python lens library for manipulating deeply nested immutable structures
GNU General Public License v3.0
313 stars 19 forks source link

Support for NamedTuples #14

Closed mvcisback closed 7 years ago

mvcisback commented 7 years ago

Hey,

If using a NamedTuple the following does not work: https://github.com/ingolemo/python-lenses/blob/f5d14a131bcf6c37f55317faf70952434c208d4a/lenses/hooks/hook_funcs.py#L371

It would require type(self)(*iterable)

I'm not sure how to best distinguish between these cases, but perhaps try both?

ingolemo commented 7 years ago

Thanks. I pushed a fix that just checks the type explicitly. Namedtuples happen to have a constructor _make that creates a namedtuple from an iterable, so I used that.

If all else fails you can just add a hook for your specific kind of namedtuple.

mvcisback commented 7 years ago

Great, is there any chance the pypi version could be upgraded?

ingolemo commented 7 years ago

Sure. Done.