I recently came across with a python snippet that would create a different object model. Part of that code countians __slots__
with __fields__
.
class Reptor(object):
__slots__ = __fields__ = 'type', 'code', 'deviated_angle'
__slots__
would creates tuple object instead of dictionary object which minimize the object size and add the immutability to it. But I can't understand what's __fields__
part in here?
And __fields__
has been used in __repr__
def __repr__(self):
fields = ', '.join(repr(getattr(self, f)) for f in self.__fields__)
return f'(type(self).__name__)({fields})'