This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Elvis.Pranskevichus
Recipients Elvis.Pranskevichus, skrah
Date 2012-11-07.19:26:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1352316377.68.0.68538809412.issue16431@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the following:

import decimal

class MyDecimal(decimal.Decimal):
    def __new__(cls, value):
        return super().__new__(cls, value)

a = decimal.Decimal('1.0')
b = MyDecimal(a)
c = MyDecimal('1.0')

print(type(a), type(b), isinstance(b, MyDecimal), type(c), isinstance(c, MyDecimal))

Running the above in 3.3 produces:

<class 'decimal.Decimal'> <class 'decimal.Decimal'> False <class '__main__.MyDecimal'> True

Which shows that Decimal.__new__(cls, Decimal()) will always return its argument regardless of cls.
History
Date User Action Args
2012-11-07 19:26:17Elvis.Pranskevichussetrecipients: + Elvis.Pranskevichus, skrah
2012-11-07 19:26:17Elvis.Pranskevichussetmessageid: <1352316377.68.0.68538809412.issue16431@psf.upfronthosting.co.za>
2012-11-07 19:26:17Elvis.Pranskevichuslinkissue16431 messages
2012-11-07 19:26:17Elvis.Pranskevichuscreate