Greetings, List!

I was browsing through the Decimal source today, and found this:

    # We're immutable, so use __new__ not __init__
    def __new__. . .
        self = object.__new__(cls)
        .
        .
        .
        return self

Out of curiousity I then tried this:
        --> import decimal
        --> d25 = decimal.Decimal(25)
        --> d25
        Decimal("25")
        --> d25._int
        (2, 5)
        --> d25._int = (1, 5)
        --> d25
        Decimal("15")
        --> d25 + 15
        Decimal("30")

If Decimals were really immutable, that should not have worked -- so in what sense are they immutable? Does Python treat them as immutable if they are created with __new__ instead of __init__?

Any pointers to appropriate docs also greatly appreciated.

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to