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 mark.dickinson
Recipients facundobatista, jjconti, mark.dickinson, rhettinger, skrah
Date 2010-01-06.10:53:39
SpamBayes Score 4.7757354e-12
Marked as misclassified No
Message-id <1262775221.37.0.670383214962.issue7633@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for the patch!

Rather than using the Decimal constructor, I think you should convert use _convert_other(..., raiseit=True):  the Decimal constructor converts strings and tuples, as well as ints and longs, while _convert_other only converts ints and longs.  Note also that the conversion shouldn't depend on the current context;  only the operation itself needs that.

Maybe it would be worth adding some tests to ensure that e.g.,

MyContext.add('4.5', 123)

raises TypeError as expected?

I agree with the observation that it's usually only necessary to convert the first argument (since the Decimal method itself converts the second).

If you like, you could also usefully deal with the NotImplemented return value by turning it into a TypeError (i.e., in the context method, check for a NotImplemented return value, and raise TypeError there if necessary).  This is only needed for the double underscore methods __add__, __sub__, etc.  associated with Python's binary operators;  the other methods shouldn't ever return NotImplemented.
History
Date User Action Args
2010-01-06 10:53:41mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, facundobatista, jjconti, skrah
2010-01-06 10:53:41mark.dickinsonsetmessageid: <1262775221.37.0.670383214962.issue7633@psf.upfronthosting.co.za>
2010-01-06 10:53:40mark.dickinsonlinkissue7633 messages
2010-01-06 10:53:39mark.dickinsoncreate