Skip to content

Support getters and setters in Argument Clinic #112205

Description

@colesbury

Feature or enhancement

In the C API, getters and setters are implemented using PyGetSetDef. Argument Clinic doesn't currently support writing getters and setters, probably because they are pretty straightforward to write manually -- there's not much argument parsing to be done.

Argument Clinic now supports the @critical_section directive, which avoids a bunch of boilerplate code when making things thread-safe with the --disable-gil builds. It would be helpful if Argument Clinic supported getters/setters so that we could avoid the critical section boilerplate in getters and setters as well.

Linked PRs

Activity

  1. colesbury commented on Nov 17, 2023

    @colesbury
    ContributorAuthor

    cc @aisk (who brought up this issue in #112116 (comment)) and @erlend-aasland for feedback

  2. corona10 commented on Nov 22, 2023

    @corona10
    Member

    Another example that needs this feature: #112298

  3. corona10 commented on Nov 22, 2023

    @corona10
    Member

    @colesbury @erlend-aasland @AlexWaygood
    (Just for example)
    What about following DSL for name setter / getter case?
    It looks similar to Java lombok annotation :(

    /*[clinic input] 
    @setter
    @getter
    @critical_section
    _io._Buffered.name
    [clinic start generated code]*/
    
  4. added a commit that references this issue on Nov 25, 2023
  5. added 3 commits that reference this issue on Nov 30, 2023
  6. corona10 commented on Dec 2, 2023

    @corona10
    Member
    /*[clinic input] 
    @getter
    @critical_section
    _io._Buffered.name
    [clinic start generated code]*/
    
    /*[clinic input] 
    @setter
    @critical_section
    _io._Buffered.name
    [clinic start generated code]*/
    

    I am working on supporting @setterwith the co-existence case of @getter.
    Separating clinic input is more straightforward and cleaner than declaring with a single input.

  7. AlexWaygood commented on Dec 2, 2023

    @AlexWaygood
    Member

    Separating clinic input is more straightforward and cleaner than declaring with a single input.

    I think it looks nicer as well — having the three stacked decorators kinda looked ugly to me. Moreover, the slightly more verbose syntax of having the two inputs separated is closer to how you'd implement a Python property with a setter. In short: good choice, IMO :-)

  8. added a commit that references this issue on Dec 10, 2023
  9. 13 remaining items

  10. added 2 commits that reference this issue on Dec 26, 2023
  11. added 6 commits that reference this issue on Feb 11, 2024
  12. added 6 commits that reference this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions