You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Derby #3: Convert 67 sites to Argument Clinic across 4 files (Windows) #64371
This issue is part of the Great Argument Clinic Conversion Derby,
where we're trying to convert as much of Python 3.4 to use
Argument Clinic as we can before Release Candidate 1 on January 19.
To possibly ease review (and for keeping track of what I'm doing), I'm linking hg.python.org/sandbox/zware#bpo-20172 where I'll try to do a commit per converted function.
The piecemeal approach sounds fine, but I'm only going to review patches once you post them here. (I'm not sure I can get to reviewing your patch today, but definitely tomorrow.)
Oh, and, p.s. I was a Win32 developer for about fifteen years. I don't touch it anymore, but I consider myself still competent to read patches for simple stuff like the registry library.
Thanks, Larry. Conversion proceeds apace in winreg.c, but I have a couple questions.
Since the comment above CConverter.format_unit says all custom converters should use 'O&' instead of defining format_unit, there must be another way to do this:
/*[python input]
class REGSAM_converter(CConverter):
type = 'REGSAM'
format_unit = 'i'
default = 0
defconverter_init(self, *, key_name=""):
ifkey_name=="":
raiseValueError('must provide the key name')
self.doc_default=self.py_default=self.c_default=key_name
[pythonstartgeneratedcode]*/
I don't know what the 'other way' is though :). The above works, but I don't understand it completely and thus don't like it. Also, it causes help(winreg.CreateKeyEx) to show "access='KEY_WRITE'" in the signature, when it should have no quotes (being a name).
Is there an easy way to give a function multiple names? OpenKey and OpenKeyEx are the same function, OpenKeyEx has been just defined by an extra methoddef pointing at OpenKey; for now I've just modified that line to make things work.
Neither of these is blocking progress, so not a huge deal other than getting a little bit of review done early.
When I wrote that I hadn't considered that people would want custom subclasses of ints. I assumed they'd be using custom converter *functions*, which of course means they'd use 'O&'. I can think of how to reword the text but for now I assume your approach for REGSAM is fine; certainly I approve of using the correct type in the generated code.
However, I doubt doc_default, py_default, and c_default should all be exactly the same. And the 'key_name' parameter seems a little awkward.
Here's something you could consider: I don't think it's documented yet (I'm going as fast as I can over here, honest) but now you can use simple constants as Python defaults. So maybe you can use REGSAM like this:
arg: REGSAM(c_default='KEY_READ') = winreg.KEY_READ
and then REGSAM could simply be an empty ("pass") subclass of int_converter.
Ahhhh, much better. An empty subclass doesn't do quite the right thing, but class REGSAM_converter(int_converter): type = 'REGSAM' does the trick (see http://hg.python.org/sandbox/zware/rev/5af08aa49631).
Thanks, Larry!
(Next will probably be trying to get a proper HKEY converter to work, but I'm holding off on that until I have most everything else clinicized first.)
Here's the complete patch for PC/winreg.c. One clinic/signature/pydoc issue I've noticed:
>>> help(winreg.HKEYType.Close)
Help on method_descriptor:
Close(...) <--- No signature
Close() <--- Extra
Closes the underlying Windows handle.
If the handle is already closed, no error is raised.
>>> winreg.HKEYType.Close.__doc__
'Close()\nCloses the underlying Windows handle.\n\nIf the handle is already clos
ed, no error is raised.'
>>> winreg.HKEYType.Close.__text_signature__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'method_descriptor' object has no attribute '__text_signature__'
My gut feeling is that it's a Clinic issue; Clinic should be adding 'self' to the signature, which should then be picked up by the __text_signature__ parser, and used by inspect and pydoc.
As far as the patch, one point I'd like some extra scrutiny on is the HKEY_converter (and C clinic_HKEY_converter). I don't understand how all of the C machinery there works properly, so I can't say with confidence that it is right. It compiles without errors and the tests pass, but beyond that, I can't guarantee anything.
Certainly, Martin. I'm in the process of getting it updated and self-reviewing again. This patch will require bpo-20586 and possibly another new Clinic feature (allowing output to multiple destinations; I have a change for that feature on my bpo-20172 sandbox branch, but don't remember why and never got an issue made for it) before commit.
I'll try to have a fresh patch up here within a week or so.
Activity
larryhastings commentedon Jan 7, 2014
This issue is part of the Great Argument Clinic Conversion Derby,
where we're trying to convert as much of Python 3.4 to use
Argument Clinic as we can before Release Candidate 1 on January 19.
This issue asks you to change the following bundle of files:
PC/msvcrtmodule.c: 18 sites
PC/winreg.c: 24 sites
PC/winsound.c: 3 sites
Modules/_winapi.c: 22 sites
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
Clinic, read the "howto":
http://docs.python.org/dev/howto/clinic.html
zware commentedon Jan 8, 2014
I'll take a stab at this one, but I may make you rue the day you said you'd review until your eyes bleed ;)
Here's a partial patch to PC/winreg.c, converting only the CloseKey function just to make sure I have some basic idea of what I'm doing.
(Also, if anyone else wants this one, please don't hesitate on account of me; just let me know and it's yours.)
zware commentedon Jan 8, 2014
To possibly ease review (and for keeping track of what I'm doing), I'm linking hg.python.org/sandbox/zware#bpo-20172 where I'll try to do a commit per converted function.
larryhastings commentedon Jan 8, 2014
The piecemeal approach sounds fine, but I'm only going to review patches once you post them here. (I'm not sure I can get to reviewing your patch today, but definitely tomorrow.)
larryhastings commentedon Jan 9, 2014
I lied, I just looked at it. You said it was only one function, so it went quickly.
It looks totally fine. In fact, Argument Clinic is generating better code than the original!
larryhastings commentedon Jan 9, 2014
Oh, and, p.s. I was a Win32 developer for about fifteen years. I don't touch it anymore, but I consider myself still competent to read patches for simple stuff like the registry library.
zware commentedon Jan 10, 2014
Thanks, Larry. Conversion proceeds apace in winreg.c, but I have a couple questions.
/*[python input]
class REGSAM_converter(CConverter):
type = 'REGSAM'
format_unit = 'i'
default = 0
(see http://hg.python.org/sandbox/zware/rev/f0662bf33e65)
I don't know what the 'other way' is though :). The above works, but I don't understand it completely and thus don't like it. Also, it causes help(winreg.CreateKeyEx) to show "access='KEY_WRITE'" in the signature, when it should have no quotes (being a name).
Neither of these is blocking progress, so not a huge deal other than getting a little bit of review done early.
larryhastings commentedon Jan 10, 2014
When I wrote that I hadn't considered that people would want custom subclasses of ints. I assumed they'd be using custom converter *functions*, which of course means they'd use 'O&'. I can think of how to reword the text but for now I assume your approach for REGSAM is fine; certainly I approve of using the correct type in the generated code.
However, I doubt doc_default, py_default, and c_default should all be exactly the same. And the 'key_name' parameter seems a little awkward.
Here's something you could consider: I don't think it's documented yet (I'm going as fast as I can over here, honest) but now you can use simple constants as Python defaults. So maybe you can use REGSAM like this:
arg: REGSAM(c_default='KEY_READ') = winreg.KEY_READ
and then REGSAM could simply be an empty ("pass") subclass of int_converter.
No convenient way yet. Let me think about it.
zware commentedon Jan 10, 2014
Ahhhh, much better. An empty subclass doesn't do quite the right thing, but
class REGSAM_converter(int_converter): type = 'REGSAM'does the trick (see http://hg.python.org/sandbox/zware/rev/5af08aa49631).Thanks, Larry!
(Next will probably be trying to get a proper HKEY converter to work, but I'm holding off on that until I have most everything else clinicized first.)
zware commentedon Jan 10, 2014
Here's the complete patch for PC/winreg.c. One clinic/signature/pydoc issue I've noticed:
>>> help(winreg.HKEYType.Close) Help on method_descriptor:Close(...) <--- No signature
Close() <--- Extra
Closes the underlying Windows handle.
>>> winreg.HKEYType.Close.__doc__ 'Close()\nCloses the underlying Windows handle.\n\nIf the handle is already clos ed, no error is raised.' >>> winreg.HKEYType.Close.__text_signature__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'method_descriptor' object has no attribute '__text_signature__'My gut feeling is that it's a Clinic issue; Clinic should be adding 'self' to the signature, which should then be picked up by the __text_signature__ parser, and used by inspect and pydoc.
As far as the patch, one point I'd like some extra scrutiny on is the HKEY_converter (and C clinic_HKEY_converter). I don't understand how all of the C machinery there works properly, so I can't say with confidence that it is right. It compiles without errors and the tests pass, but beyond that, I can't guarantee anything.
zware commentedon Jan 10, 2014
PC/winsound.c went pretty quick and easy.
zware commentedon Jan 11, 2014
Here's msvcrt.
zware commentedon Jan 13, 2014
And here is the patch to _winapi.c.
10 remaining items
zware commentedon Jan 25, 2014
Ok, v5 should be ready to go in, so long as you don't see anything scary.
zware commentedon Jan 28, 2014
I have high hopes for this latest update :)
loewis commentedon Jul 27, 2014
2 hunks of _winapi.c currently fail to apply. Can you please update the patch?
zware commentedon Jul 28, 2014
Certainly, Martin. I'm in the process of getting it updated and self-reviewing again. This patch will require bpo-20586 and possibly another new Clinic feature (allowing output to multiple destinations; I have a change for that feature on my bpo-20172 sandbox branch, but don't remember why and never got an issue made for it) before commit.
I'll try to have a fresh patch up here within a week or so.
zware commentedon Aug 4, 2014
Here's an updated patch. It includes the patch from bpo-20586 for proper signature/docstring output in _winapi.
zware commentedon Apr 14, 2015
Latest patch ought to be good, if anybody feels like rubber-stamping a 5000 line patch :)
zooba commentedon Apr 15, 2015
Reviewed v8 and it looks good to me. Not a clinic expert, but I assume that it'll fail at build if anything is really wrong.
larryhastings commentedon Apr 15, 2015
If
then the Clinic conversion can generally be considered a success.
python-dev commentedon May 13, 2015
New changeset d3582826d24c by Zachary Ware in branch 'default':
Issue bpo-20172: Convert the winsound module to Argument Clinic.
https://hg.python.org/cpython/rev/d3582826d24c
New changeset 6e613ecd70f0 by Zachary Ware in branch 'default':
Issue bpo-20172: Convert the winreg module to Argument Clinic.
https://hg.python.org/cpython/rev/6e613ecd70f0
New changeset c190cf615eb2 by Zachary Ware in branch 'default':
Issue bpo-20172: Convert the msvcrt module to Argument Clinic.
https://hg.python.org/cpython/rev/c190cf615eb2
New changeset 4cf37a50d91a by Zachary Ware in branch 'default':
Issue bpo-20172: Convert the _winapi module to Argument Clinic.
https://hg.python.org/cpython/rev/4cf37a50d91a
zware commentedon May 13, 2015
Committed, thanks for the reviews, guidance, and patience!
python-dev commentedon May 13, 2015
New changeset c8adc2c13c8b by Zachary Ware in branch 'default':
Issue bpo-20172: Update clinicizations to current clinic.
https://hg.python.org/cpython/rev/c8adc2c13c8b