New submission from Elvis Pranskevichus:

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, 

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.

messages: 175121
nosy: Elvis.Pranskevichus, skrah
priority: normal
severity: normal
status: open
title: CDecimal disregards subclass passed into __new__ when value argument is 
an instance of Decimal
type: behavior
versions: Python 3.3, Python 3.4

Python tracker <>
Python-bugs-list mailing list

Reply via email to