prePEP: Money data type

Alex Martelli aleax at aleax.it
Mon Oct 20 15:11:48 EDT 2003


Batista, Facundo wrote:
   ...
> #- a very toy example, a meant-as-immutable Money that only holds an
> #- amount and lets you sum a number to that returning a new instance:
> #-
> #- class Money(object):
> #-     def __init__(self, amount): self.amount = amount
> #-     def __add__(self, other):
> #-         return self.__class__(self.amount + other)
> 
> Very good idea, Alex. Any test case that test this?

You mean, as in (method of the appropriate TestCase subclass):

    def testSameclass(self):
        class MyMoney(Money): pass
        x = MyMoney() + 3
        self.assertEquals(type(x), MyMoney)

???


Alex





More information about the Python-list mailing list