Re: [PATCH] Fix conversion for Decimal arguments in plpython functions
От | Claudio Freire |
---|---|
Тема | Re: [PATCH] Fix conversion for Decimal arguments in plpython functions |
Дата | |
Msg-id | CAGTBQpZzx0KNyiy1bwScC3JHyL7WWDQVOBxA+LLJ4C+abfQtcg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: [PATCH] Fix conversion for Decimal arguments in plpython functions (Peter Eisentraut <peter_e@gmx.net>) |
Список | pgsql-hackers |
On Fri, Jul 5, 2013 at 11:47 PM, Peter Eisentraut <peter_e@gmx.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..
В списке pgsql-hackers по дате отправления: