I want to write a suite of methods that act as getters when passed zero arguments and as setters when passed a single argument. I have two two reasonable implementations, shown below. Is one better than the other, or is there perhaps an even better way?
class Thing(object): def __init__(self): self._size = 0 def sizeA(self, *args): if not args: return self._size self._size = args return self UNIQUE_ID =  def sizeB(self, arg=UNIQUE_ID): if arg is self.UNIQUE_ID: return self._size self._size = arg return self
A couple of comments:
sizeA() benchmarks faster than
sizeB(), but doesn't give me argument count checking.
sizeB() works, but it depends on
UNIQUE_ID being invariant, and I wonder if there are circumstances (e.g. pickling) that would cause it to break.
P.S.: Though I'm currently developing in python-2.7, I'm open to python-3.x specific answers as appropriate.