Re: [PATCH] Fix conversion for Decimal arguments in plpython functions

From: Claudio Freire <klaussfreire(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Steve Singer <steve(at)ssinger(dot)info>, Szymon Guz <mabewlun(at)gmail(dot)com>, Ronan Dunklau <rdunklau(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Fix conversion for Decimal arguments in plpython functions
Date: 2013-07-06 04:23:46
Message-ID: CAGTBQpZzx0KNyiy1bwScC3JHyL7WWDQVOBxA+LLJ4C+abfQtcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 5, 2013 at 11:47 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> On Fri, 2013-06-28 at 17:29 -0300, Claudio Freire wrote:
>> Why not forego checking of the type, and instead check the interface?
>>
>> plpy.info(x.as_tuple())
>>
>> Should do.
>>
>> >>> d = decimal.Decimal((0,(3,1,4),-2))
>> >>> d.as_tuple()
>> DecimalTuple(sign=0, digits=(3, 1, 4), exponent=-2)
>
> I think that potentially exposes us to more version differences and
> such, and it doesn't really add much value in the test output.

Why?

That interface is documented, and Python guys aren't likely to change
it, not even in alternative implementations.

Besides, this is the "zen" way of checking. Python uses duck typing,
so checking the actual class of stuff is frowned upon. The "Pythonic"
way to write tests is to check the expected behavior of returned
objects. In this case, that it has an as_tuple that returns the right
thing.

You could also check other interesting behavior if you want, including
its string representation, that it can be converted to float, that two
decimals can be operated upon and that they preserve the right amount
of precision, etc..

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2013-07-06 04:25:22 review: WITH CHECK OPTION
Previous Message Peter Eisentraut 2013-07-06 02:47:58 Re: [PATCH] Fix conversion for Decimal arguments in plpython functions