3 ms·
I do not think it's simple to remove the __getitem__ lookup behavior from this template. To start with, forename depends on _itemgetter(0). I might as well re-
by eesmith 9y ago
I do not think it's simple to remove the __getitem__ lookup behavior from this template. To start with, forename depends on _itemgetter(0).
I might as well re-write it as:
class FullName(object):
__slots__ = ("_forename", "_surname")
def __init__(self, forename, surname):
self._forename = forename
self._surname = surname
def __repr__(self):
return "%s(forename=%r, surname=%r)" % (
self.__class__.__name__, self._forename, self._surname)
@property
def forename(self):
return self._forename
@property
def surname(self):
return self._surname
That took about two minutes to write. How long does it take you to rewrite the _source so it doesn't support __getitem__ or __len__?