[Python-Dev] Using argument clinic to replace timemodule.c:parse_time_t_args()

Larry Hastings larry at hastings.org
Tue Jan 21 11:39:52 CET 2014


On 01/21/2014 12:59 AM, Serhiy Storchaka wrote:
> 21.01.14 04:44, Nikolaus Rath написав(ла):
>> Serhiy Storchaka <storchaka at gmail.com> writes:
>>> 20.01.14 06:19, Nikolaus Rath написав(ла):
>>>> This works if the user calls time.gmtime(None), but it fails for
>>>> time.gmtime(). It seems that in that case my C converter function is
>>>> never called.
>>>>
>>>> What's the trick that I'm missing?
>>>
>>> /*[clinic input]
>>> time.gmtime
>>>
>>>      [
>>>      seconds: time_t
>>>      ]
>>>      /
>>>
>>
>> Ahh, interesting. So this works, but now the C default is evaluated even
>> if the user passed an argument (so that answers my question about
>> decreased performance in the other subthread). The generated code is:
>
> Don't use time(NULL) as C default. Instead check group_right_1 and 
> call time(NULL) explicitly.

While this "trick" works, it abuses optional groups.  Optional groups 
are intended as a last resort, for semantics that can't be expressed any 
other way.  The semantics of time.gmtime() are very easily expressed 
using normal Python syntax.  Please don't use optional groups here.


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140121/24791ca9/attachment.html>


More information about the Python-Dev mailing list