Paste: Stupid Python Trick

Author: Screwtape
Mode: python
Date: Tue, 30 Mar 2010 10:20:28
Plain Text |
#!/usr/bin/python

class LengthAccumulator(object):
	def __init__(self):
		self.number = 1

	def __neg__(self):
		self.number += 1


class LengthLiteral(object):

	def __neg__(self):
		return LengthAccumulator()

	def __sub__(self, other):
		if isinstance(other, LengthAccumulator):
			return other.number + 1
		else:
			return 1


I = LengthLiteral()


if __name__ == "__main__":

	assert      I-I == 1
	assert     I--I == 2
	assert I------I == 6

Annotation: TypeError for assert I------I == 6

Author: apgwoz
Mode: factor
Date: Thu, 1 Apr 2010 18:04:40
Plain Text |
class LengthAccumulator(object):
    def __init__(self):
        self.number = 1
    def __neg__(self):
        self.number += 1
        return self

# otherwise I get a TypeError

Annotation: yyy

Author: uuu
Mode: doxygen
Date: Fri, 2 Apr 2010 13:24:26
Plain Text |
ok?

Annotation: j/

Author: uj
Mode: clips
Date: Fri, 2 Apr 2010 13:25:07
Plain Text |
uy/t/u

New Annotation

Summary:
Author:
Mode:
Body: