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

TypeError: 'AttMap' object is not callable #73

Open
stolarczyk opened this issue Nov 19, 2020 · 1 comment
Open

TypeError: 'AttMap' object is not callable #73

stolarczyk opened this issue Nov 19, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@stolarczyk
Copy link
Member

When one of the items in a mapping is named "items", the __repr__ fails.

That's because items() method is called on the object in _data_for_repr()

def _data_for_repr(self):
"""
Hook for extracting the data used in the object's text representation.
:return Iterable[(hashable, object)]: collection of key-value pairs
to include in object's text representation
"""
return filter(lambda kv: not self._excl_from_repr(kv[0], self.__class__),
self.items())

In [35]: AttMap({'attr1': 'val1', 'items': {'attr2_1': 'string'}})                                                                                                                                        
Out[35]: ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    397                             meth = cls._repr_pretty_
    398                             if callable(meth):
--> 399                                 return meth(obj, self, cycle)
    400                         if cls is not object \
    401                                 and callable(cls.__dict__.get('__repr__')):

~/code/attmap/attmap/attmap.py in _repr_pretty_(self, p, cycle)
    121         :return str: text representation of the instance
    122         """
--> 123         return p.text(repr(self) if not cycle else '...')

~/code/attmap/attmap/_att_map_like.py in __repr__(self)
     64     def __repr__(self):
     65         return self._render(self._simplify_keyvalue(
---> 66             self._data_for_repr(), self._new_empty_basic_map))
     67 
     68     def _render(self, data, exclude_class_list=[]):

~/code/attmap/attmap/_att_map_like.py in _data_for_repr(self)
    171         """
    172         return filter(lambda kv: not self._excl_from_repr(kv[0], self.__class__),
--> 173                       self.items())
    174 
    175     def _excl_from_eq(self, k):

TypeError: 'AttMap' object is not callable
@stolarczyk stolarczyk added the bug Something isn't working label Nov 19, 2020
@vreuter
Copy link
Member

vreuter commented Feb 7, 2021

Has work already been done on this? If not, you could try something for L172-173 along the lines of:

return [(k, self[k]) for k in self if not self._excl_from_repr(k, self.__class__)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants