-
-
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 #11: Convert 50 sites to Argument Clinic across 9 files #64379
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 |
I'm attaching my conversion of deque.rotate and _count_elements in Modules/_collectionsmodule.c. There remain 3 other functions in that module to be converted. One is deque_init which returns int; Larry said (on IRC) to hold off with that for now. The other two are dequeiter_new and dequereviter_new, which use the O! format, which I am unsure how to handle. |
Attaching patch for complete conversion of Objects/unicodeobject.c. Notes:
|
Attached patch for AC conversion of Objects/stringlib/transmogrify.h. Converting the functions in this file required changes to Objects/bytesobject.c and Objects/bytearrayobject.c. Those changes are in the patch as well. The conversion of those files is part of bpo-20179 (Derby #10). I'm adding a comment on that issue as well with a reference to this. |
Attaching a new patch for complete conversion of Objects/unicodeobject.c. This new patch also converts all other possible unicode methods, Unicode methods still not converted, probably impossible to convert:
|
Attached nearly complete conversion of Modules/_collectionsmodule.c. I've converted all functions using PyArg_* functions, including __new__ methods, but not deque.__init__. I'm attaching a separate patch for deque.__init__. |
Attached a patch converting deque.__init__ in Modules/_collectionsmodule.c, which completes the conversion of this file. This patch depends Larry's first patch in bpo-20341 (Argument Clinic: add "nullable ints"). This functionality is used to simplify the existing code for accepting None for the 'maxlen' argument to deque.__init__. If needed I can supply a patch which does not depend on Larry's patch. |
Attached is a complete conversion of Modules/_randommodule.c. Three _random.Random methods were converted: seed, getrandbits and __new__. There's was an problem converting _random.Random.__new__. I overcame it cleanly and think this patch is good. Details about the problem follow. bpo-1486663 made various __new__ methods of built-in classes only do a '_PyArg_NoKeywords' check if the type is the class itself, i.e. not for sub-classes. This is to allow sub-classes to accept keyword arguments. This means that for classes that do this, like _random.Random, converting using AC makes it so subclasses can't accept keyword arguments (unless the subclasses implement __new__ properly). Still, it is possible to convert _random.Random.__new__ and also override __new__ in random.Random (random != _random, and random.Random subclasses _random.Random). This way subclasses of the latter can accept keyword arguments. Since anyone sub-classing _random.Random instead of random.Random can be expected to know to override __new__ or switch to random.Random, I think this is a good solution for this case. The attached patch does as I suggest above and passes all tests in test_random, including 'test_random_subclass_with_kwargs' which checks this issue. Just to be sure, I also ran the entire test suite, and all tests pass. |
Attached complete conversion of Modules/xxlimited.c, Modules/xxmodule.c and Modules/xxsubtype.c. There are no tests for these and the code is not used by anything AFAIK, so I was extra careful and went over the diffs manually once everything was done. |
I think we should probably not convert xx*.c. They are for newcomers |
I thought AC was how all new modules were supposed to be written. If so, the example modules should definitely use AC! Also note that once the generated code is in separate files, the code in the origin files will be simpler and clearer. |
The vast majority of C modules are in third-party packages. I doubt that external |
Thanks, Stefan. I hadn't realized that the xx files were targeted mainly a third-party developers. In this case, I can see the sense in not converting them. I only wish someone had said something *before* I went ahead and converted them... |
Yeah, sorry. It's also just my personal opinion. BTW, xxmodule did not compile |
When AC moves from internal-only tool to supported tool we'll want to convert the xx stuff. But yeah I reckon it makes sense to not convert them yet. The list of files is really more "here's the list of stuff to check out and convert if necessary". best judgement is always called for. |
Attached is a complete AC conversion of itertools. This is a large conversion, so I was extra careful. I even went over the entire diff manually to check for any errors. Compilation runs without warnings and the entire test suite passes. Notes:
|
And at that, I've finished the conversion of this entire Derby group! Woohoo! (except for itertools.repeat which is pending discussion) |
For the unicodeobject changes, see Rietveld. In addition, it produces many cast errors from PyUnicodeObject* to PyObject*. Otherwise, it looks fine - please apply (after these fixes). |
All the Derby patches should only go into trunk at this point. |
Sadly, for political reasons, it's best that we not convert collections, itertools, or random for now. I'll update this issue if the situation changes. Sorry about that! |
Attaching new patch for unicodeobject.c, which supersedes the previous patches. I've changed the name of the parameter of str.join() to "iterable" to match the docs. (In the previous patch I had changed it from "seq" to "iterable_of_strings".) I also fixed two minor comments on the doc strings from Martin. With this, AFAIK, unicodeobject.c should be good to go. |
Here's a new patch for Objects/unicodeobject.c with all of Serhiy's suggestions integrated. |
The patch causes a lot of warnings like Objects/unicodeobject.c: In function ‘unicode_title_impl’: |
Version of patch with PyUnicodeObject * warnings fixed. |
unicodeobject.c.v5.patch LGTM. |
Hurrah! And that seems to be it for this group, since collections, itertools and random are not to be converted at this point, as well as the Modules/xx*.c files, and the stringlib files probably require overly extensive changes for conversion. |
Well, there are also technical reasons. For example, when reviewing a huge patch at the beginning of this year, the sections that touched AC took me 10 times longer to review than the rest. |
New changeset 27dc9a1c061e by INADA Naoki in branch 'default': |
Thank you, Martin and Serhiy. As http://bugs.python.org/issue20180#msg247987 , remained module to converted But docstrings of methods in transmogrify.h were moved to bytes_methods.c in bpo-26765. May I close this issue for now? |
Seems you haven't updated generated AC files. |
New changeset 01b06ca45f64 by INADA Naoki in branch 'default': |
Uhhh! I'm sorry. |
For str.format_map(mapping), yes the parsing happens in Objects/stringlib/unicode_format.h, but I don’t see that as a big problem. Moving this back to “needs patch”, assuming it is okay to convert format_map(). Other than from that, there are just tricky things left like the str() constructor, str.format(*args, **kwargs) (see bpo-20291), and the shared code in Objects/stringlib/find.h and Objects/stringlib/transmogrify.h. I don’t know what to do about those. |
Seems Raymond have changed his mind about using Argument Clinic in itertools (msg302908). Tal, do you mind to update your itertools patch and create a pull request? |
Id be happy to update the itertools patch. I haven't been following AC work for quite a while. I would expect this to entail:
Would you also prefer this in the form of a GitHub PR? |
All correct. The final patch should be in the form of GitHub PR. Don't specify the self parameter explicitly, just rename the corresponding variable. The rest of the patch LGTM. |
What about islice? Does AC now support complex enough signatures to support it? If not, should I leave the comment as is? |
Keep islice() non-converted. For the r parameter of permutations() use "r: object = None". |
As far as I can tell, with the creation of a separate clinic/itertools.c.h, the typedefs etc. need to be moved to the top of the file so that the #include can come after the typedefs and before the rest of the code which references clinic output. Is this indeed the way to go? |
Yes, it is. Actually the #include should be before lists of methods and static PyTypeObject initializers. I think it is better to move all method lists and type initializers to the bottom of the file. |
See PR 4117 on GitHub with the itertools AC conversion. |
To enable progressing with this in smaller steps, I created PR 4170 which converts only itertools.groupby and the intertnal _grouper with minimal required changes. |
IMO we should create new issues for AC conversion of the collections and random modules (assuming they haven't been converted yet), and close this issue. |
I agree with you. Let's finish derby. |
See updated PR for Objects/stringlib/transmogrify.h in #52287. |
New changeset c929df3 by Tal Einat in branch 'master': |
Now that transmogrify is done, the only open question is about itertools and collections.
|
Now just the collections module is left from this group. Raymond, what would you like done with it WRT AC conversion, if at all? |
I would like to pass on the collections module. Having looked at the patch, I think the code is currently better as is. That bring this one Derby to a close. Congratulations :-) |
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: