Skip to content
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 #3: Convert 67 sites to Argument Clinic across 4 files (Windows) #64371

Closed
larryhastings opened this issue Jan 7, 2014 · 34 comments
Closed
Assignees
Labels
extension-modules C modules in the Modules dir topic-argument-clinic type-bug An unexpected behavior, bug, or error

Comments

@larryhastings
Copy link
Contributor

BPO 20172
Nosy @loewis, @larryhastings, @zware, @zooba
Dependencies
  • bpo-20189: inspect.Signature doesn't recognize all builtin types
  • bpo-20586: Argument Clinic: functions with valid sig but no docstring have no text_signature
  • Files
  • conglomerate.v2.diff
  • conglomerate.v3.diff
  • conglomerate.v4-two-pass.diff
  • conglomerate.v5-post-20189.diff
  • conglomerate.v6-post-20326.diff
  • issue20172.v7.diff
  • issue20172.v8.diff
  • 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:

    assignee = 'https://github.com/zware'
    closed_at = <Date 2015-05-13.06:34:00.754>
    created_at = <Date 2014-01-07.23:45:08.589>
    labels = ['extension-modules', 'type-bug', 'expert-argument-clinic']
    title = 'Derby #3: Convert 67 sites to Argument Clinic across 4 files (Windows)'
    updated_at = <Date 2015-05-13.15:58:54.139>
    user = 'https://github.com/larryhastings'

    bugs.python.org fields:

    activity = <Date 2015-05-13.15:58:54.139>
    actor = 'python-dev'
    assignee = 'zach.ware'
    closed = True
    closed_date = <Date 2015-05-13.06:34:00.754>
    closer = 'zach.ware'
    components = ['Extension Modules', 'Argument Clinic']
    creation = <Date 2014-01-07.23:45:08.589>
    creator = 'larry'
    dependencies = ['20189', '20586']
    files = ['33504', '33606', '33661', '33695', '33775', '36256', '39016']
    hgrepos = ['216']
    issue_num = 20172
    keywords = ['patch']
    message_count = 34.0
    messages = ['207617', '207703', '207705', '207715', '207718', '207719', '207834', '207854', '207864', '207876', '207881', '207898', '208004', '208052', '208064', '208080', '208149', '208198', '208231', '208742', '208749', '208750', '208969', '209156', '209560', '224118', '224180', '224752', '241009', '241117', '241130', '243044', '243045', '243100']
    nosy_count = 5.0
    nosy_names = ['loewis', 'larry', 'python-dev', 'zach.ware', 'steve.dower']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20172'
    versions = ['Python 3.5']

    @larryhastings
    Copy link
    Contributor Author

    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

    @larryhastings larryhastings added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Jan 7, 2014
    @zware
    Copy link
    Member

    zware commented 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
    Copy link
    Member

    zware commented 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
    Copy link
    Contributor Author

    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
    Copy link
    Contributor Author

    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
    Copy link
    Contributor Author

    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
    Copy link
    Member

    zware commented Jan 10, 2014

    Thanks, Larry. Conversion proceeds apace in winreg.c, but I have a couple questions.

    1. 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

        def converter_init(self, *, key_name=""):
            if key_name == "":
                raise ValueError('must provide the key name')
            self.doc_default = self.py_default = self.c_default = key_name
    [python start generated code]*/

    (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).

    1. 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.

    @larryhastings
    Copy link
    Contributor Author

    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
    Copy link
    Member

    zware commented 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
    Copy link
    Member

    zware commented 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.

    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.

    @zware
    Copy link
    Member

    zware commented Jan 10, 2014

    PC/winsound.c went pretty quick and easy.

    @zware
    Copy link
    Member

    zware commented Jan 11, 2014

    Here's msvcrt.

    @zware
    Copy link
    Member

    zware commented Jan 13, 2014

    And here is the patch to _winapi.c.

    @larryhastings
    Copy link
    Contributor Author

    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.

    This innocent little comment has derailed my whole day. You're right, 'self' should be in the signature. But not always! And then in
    inspect.Signature we need to strip it off for bound methods.

    In case you're curious, this work is happening in a separate branch, and tracked in a different issue (bpo-20189).

    @larryhastings
    Copy link
    Contributor Author

    Filed comments on everything.

    @zware
    Copy link
    Member

    zware commented Jan 14, 2014

    Sandbox repo updated. It is currently using an older version of clinic; running current clinic on the winreg.c in the tip of the sandbox produces this traceback:

    Traceback (most recent call last):
      File "Tools\clinic\clinic.py", line 2981, in <module>
        sys.exit(main(sys.argv[1:]))
      File "Tools\clinic\clinic.py", line 2977, in main
        parse_file(filename, output=ns.output, verify=not ns.force)
      File "Tools\clinic\clinic.py", line 1132, in parse_file
        cooked = clinic.parse(raw)
      File "Tools\clinic\clinic.py", line 1082, in parse
        parser.parse(block)
      File "Tools\clinic\clinic.py", line 2259, in parse
        self.state(line)
      File "Tools\clinic\clinic.py", line 2633, in state_parameter_docstring
        return self.next(self.state_parameter, line)
      File "Tools\clinic\clinic.py", line 2287, in next
        self.state(line)
      File "Tools\clinic\clinic.py", line 2531, in state_parameter
        value = eval(py_default)
      File "<string>", line 1, in <module>
    NameError: name 'winreg' is not defined

    I'm not terribly sure about the error handling with the return converters, that will need some extra scrutiny. I may have it completely wrong :).

    @larryhastings
    Copy link
    Contributor Author

    Zachary: If you refresh your copy of trunk, you can now "clone" functions. See the howto for the syntax.

    The failure you were seeing was in some code that I just rewrote (see bpo-20226). I'd be interested if you could apply that patch and try your code again. Or just wait maybe twelve hours, hopefully I'll have landed the patch by then.

    (Yeah, it's kind of a moving target. I'm trying to keep the pace up during the Derby.)

    @zware
    Copy link
    Member

    zware commented Jan 15, 2014

    About cloning:

    Cloned functions still expect their own impl function. In current winreg, OpenKey and OpenKeyEx literally are the same function by two names; is the best approach for this to define winreg_OpenKeyEx_impl as return winreg_OpenKey_impl(module, key, sub_key, reserved, access);?

    As stated in bpo-20226, that patch works fine with my conversions. Once the 20226 patch lands, I'll get a comprehensive patch for this issue posted. Until then, I've branched the sandbox repo yet again; future_clinic_20172 contains the 20226 patch, along with the necessary updates to these files and further changes using the new features that aren't in trunk yet.

    @larryhastings
    Copy link
    Contributor Author

    is the best approach for this to define winreg_OpenKeyEx_impl
    as return winreg_OpenKey_impl(module, key, sub_key, reserved, access);?

    Sounds good to me.

    @zware
    Copy link
    Member

    zware commented Jan 22, 2014

    Ok, new conglomerate patch is posted; includes a few more return conversions (particularly in msvcrt) and a few other minor changes compared to the previous conglomerate. I would call this one a commit candidate, pending your review. I don't plan to commit this one, though; I want to switch each of them to some manner of buffered output first, but I figured this form would be easier to review. I'll post the buffered patch as soon as it's ready, you can review whichever one you actually prefer :)

    @zware
    Copy link
    Member

    zware commented Jan 22, 2014

    Marking bpo-20189 as a dependency; winreg.HKEYType and _winapi.Overlapped need the signature fixes provided by bpo-20189 before commit.

    @zware
    Copy link
    Member

    zware commented Jan 22, 2014

    And scratch v3 being commit-candidate. I forgot to add an HKEY return converter to winreg (could have sworn I had done that, but I have no record of it), and my return converters in msvcrt are messy.

    @zware
    Copy link
    Member

    zware commented Jan 23, 2014

    Ok, here's a new patch. This one fixes the issues I found in my last patch (HKEY return converter in winreg, mess from previous return converter attempts in msvcrt), and switches all four modules to a two-pass output scheme. This should be basically what I want to commit, once 20189 is committed.

    If you'd like a non-two-pass patch for review, let me know.

    @zware
    Copy link
    Member

    zware commented Jan 25, 2014

    Ok, v5 should be ready to go in, so long as you don't see anything scary.

    @zware
    Copy link
    Member

    zware commented Jan 28, 2014

    I have high hopes for this latest update :)

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jul 27, 2014

    2 hunks of _winapi.c currently fail to apply. Can you please update the patch?

    @zware
    Copy link
    Member

    zware commented 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
    Copy link
    Member

    zware commented Aug 4, 2014

    Here's an updated patch. It includes the patch from bpo-20586 for proper signature/docstring output in _winapi.

    @zware
    Copy link
    Member

    zware commented Apr 14, 2015

    Latest patch ought to be good, if anybody feels like rubber-stamping a 5000 line patch :)

    @zooba
    Copy link
    Member

    zooba commented 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
    Copy link
    Contributor Author

    If

    • the diff looks clean
    • it compiles without any *new* (sigh) errors, and
    • it passes the unit test suite without any *new* (sigh) failures,
      then the Clinic conversion can generally be considered a success.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented 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
    Copy link
    Member

    zware commented May 13, 2015

    Committed, thanks for the reviews, guidance, and patience!

    @zware zware closed this as completed May 13, 2015
    @zware zware self-assigned this May 13, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented 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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir topic-argument-clinic type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants