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

Bug: Composing Fork Not Possible #29

Closed VRehnberg closed 3 years ago

VRehnberg commented 3 years ago

Code

lens.Fork()._compose_optic(lens).modify(lambda x: x)

Traceback

Traceback (most recent call last): File "", line 1, in File "/home/viktor/miniconda3/envs/functorch/lib/python3.9/site-packages/lenses/ui/init.py", line 156, in _compose_optic return UnboundLens(self._optic.compose(optic)) File "/home/viktor/miniconda3/envs/functorch/lib/python3.9/site-packages/lenses/optics/base.py", line 235, in compose return ComposedLens([self]).compose(other) File "/home/viktor/miniconda3/envs/functorch/lib/python3.9/site-packages/lenses/optics/base.py", line 617, in compose if result.kind() is None: File "/home/viktor/miniconda3/envs/functorch/lib/python3.9/site-packages/lenses/optics/base.py", line 254, in kind if self._is_kind(optic): File "/home/viktor/miniconda3/envs/functorch/lib/python3.9/site-packages/lenses/optics/base.py", line 625, in _is_kind return all(lens._is_kind(cls) for lens in self.lenses) File "/home/viktor/miniconda3/envs/functorch/lib/python3.9/site-packages/lenses/optics/base.py", line 625, in return all(lens._is_kind(cls) for lens in self.lenses) TypeError: 'UnboundLens' object is not callable

Problem

base.py:625

return all(lens._is_kind(cls) for lens in self.lenses)

lens._is_kind is UnboundLens(GetZoomAttrTraversal('_is_kind')) because of this function

ingolemo commented 3 years ago

lens is not a valid argument for _compose_optic. That's an internal method that's only supposed to be used with internal objects. If you want to compose two lenses you use the & operator:

(lens.Fork() & lens).modify(lambda x: x)
VRehnberg commented 3 years ago

Ok, thanks.