[Python-checkins] r60712 - python/trunk/Lib/rational.py

Nick Coghlan ncoghlan at gmail.com
Sun Feb 10 23:29:46 CET 2008


mark.dickinson wrote:
> Author: mark.dickinson
> Date: Sun Feb 10 15:58:38 2008
> New Revision: 60712
> 
> Modified:
>    python/trunk/Lib/rational.py
> Log:
> Turn classmethods into staticmethods, and avoid calling the constructor
> of subclasses of Rational.  (See discussion in issue #1682.)

I looked at the issue, and didn't see any real rationale for this 
change. Alternate constructors should be implemented as classmethods so 
that they exhibit similar behaviour to __new__.

The other operations (like __add__) are different - for those, the order 
in which subclasses are invoked is defined such that subclasses can 
override the return type if they want to.

More generally, the constructor signature is an important part of the 
subclassing API - messing with it to not accept inputs that the parent 
class accepts will quite easily break methods inherited from the parent 
class. The onus is on the subclass which breaks the constructor 
signature to also override any other methods which relied on that signature.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-checkins mailing list