-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derby #8: Convert 28 sites to Argument Clinic across 2 files #64376
Comments
This issue is part of the Great Argument Clinic Conversion Derby, This issue asks you to change the following bundle of files: Talk to me (larry) if you only want to attack part of a bundle. For instructions on how to convert a function to work with Argument |
Please take out _decimal.c. It has a huge test suite that would break entirely. |
Absolutely. decimal is a very special case. Whoever takes over this issue: please ignore the part about _decimal.c. |
I have started working on this (partial patch attached), but I am unsure how to handle cases where the docstring definition utilizes a macro. For example: PyDoc_STRVAR(strftime_doc, I don't think STRFTIME_FORMAT_CODES will be expanded if I put it into the [clinic] comment section. Should I include the contents verbatim? Or do not convert these functions to argument clinic? |
That macro, STRFTIME_FORMAT_CODES, is only used in two functions. If it were me I'd just copy and paste the text into both functions. |
Will do. Another question: what should I do with return annotations, e.g. the "-> dict" part in "get_clock_info(name: str) -> dict\n Should I drop that part? In the clinic howto, I couldn't find anything about return annotations (only that parameter annotations are unsupported). |
One more question: what's a good way to find sites that need changes? Searching for "PyArg_" finds both converted and unconverted functions... |
Yes, you should drop things that look like return annotations in the original docstring. I don't have a magic formula for finding unchanged functions, sorry. |
Here is a patch for timemodule.c. I have converted everything except:
|
Hmm. After reading some of the threads on python-dev, I'm now confused if I did the conversion of optional arguments correctly. Should something like "strftime(format[, tuple])" be converted using optional groups, or should tuple become a parameter with a default value? (so far, I have done the latter). |
Optional groups really are only for cases when that's the behavior But if the function can be expressed with normal positional parameters and default values, that's best. |
As discussed on devel, here's an updated patch for timemodule.c that You probably want to take a close look at what I did to the strptime As far as I can see, this completes the conversion for timemodule.c. I'll This is probably already planned, but since I haven't seen it in
|
(I already sent this to python-dev, but maybe it makes more sense to have these thoughts together with the patch) After looking at the conversion of parse_time_t_args again, I think I lost track of what we're actually gaining with this procedure. If all we need is a type that can distinguish between a valid time_t value and a default value, why don't we simply use PyObject? In other words, what's the advantage of the extra custom strict, plus the custom C converter function, plus the custom converter python class over: static int
PyObject_to_time_t(PyObject *obj, time_t *when)
{
if (obj == NULL || obj == Py_None)
*when = time(NULL);
else if (_PyTime_ObjectToTime_t(obj, when) == -1)
return 0;
return 1;
} /*[clinic input]
[...] static PyObject *
time_gmtime_impl(PyModuleDef *module, PyObject *seconds)
{
PyObject *return_value = NULL;
time_t when;
if(!PyObj_to_time_t(seconds, &when))
return NULL; [...] To me this version looks shorter and clearer. |
I've attached updated patches to reflect the recent changes in the derby policy. part1 is the part of the patch that is suitable for 3.4. part2 are the changes that have to wait for 3.5 (mostly because of default values). |
I'll wait with working on _datetimemodule.c until someone had a chance to look over my _timemodule.c patch. (I want to make sure I'm following the right procedure). |
Regarding the handling of time_t arguments which can be None, I agree that the second version (without custom convertors) is simpler and clearer while having no disadvantage that I can see. I'd like to review the rest of the patches, but you mention changes to the AC policy regarding 3.4 and 3.5 and I can't find a reference to these changes or to the new policy. |
Tal, I was referring to this mail: https://mail.python.org/pipermail/python-dev/2014-January/132066.html |
All the Derby patches should only go into trunk at this point. |
The modern workflow requires creating a PR on GitHub. Nikolaus, do you mind to convert your patch to a PR? |
Sorry, no. I have long lost context and interest in this. |
I have created a PR for Modules/timemodule.c. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: