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

gh-104469 : Convert _testcapi/dict.c to use AC #107859

Closed
wants to merge 2 commits into from

Conversation

jamie2779
Copy link

@jamie2779 jamie2779 commented Aug 11, 2023

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@jamie2779
Copy link
Author

jamie2779 commented Aug 11, 2023

@corona10

@corona10 corona10 self-assigned this Aug 11, 2023
_testcapi.dict_getitemstringref
obj: object
value: object
attr_name: str(accept={robuffer}, zeroes=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @erlend-aasland and @AlexWaygood it doesn't work when we use str(accept={str, NoneType}, zeroes=True) grammar even if documentation support it. Would you like to take a look?

Error in file 'Modules/_testcapi/dict.c' on line 260:
str_converter: illegal combination of arguments (frozenset({<class 'NoneType'>, <class 'str'>}), False, True)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are inaccurate; the accept parameter should be accept={robuffer, str, NoneType}. See the definition in clinic.py:

r('z#', zeroes=True, accept={robuffer, str, NoneType})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it is possible to just use the legacy converter:

Suggested change
attr_name: str(accept={robuffer}, zeroes=True)
attr_name: 'z#'

_testcapi.dict_getitemref
obj: object
attr_name: object
value: object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct; dict_getitemref only takes two positional-only arguments: obj and attr_name.

/*[clinic input]
_testcapi.dict_getitemstringref
obj: object
value: object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. value is not part of the spec of this method; dict_getitemstringref only takes two positional-only arguments.

Comment on lines 311 to 312
value: object
key: str(accept={robuffer}, zeroes=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is incorrect. It should be mapping, key, value.

_testcapi.dict_getitemstringref
obj: object
value: object
attr_name: str(accept={robuffer}, zeroes=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are inaccurate; the accept parameter should be accept={robuffer, str, NoneType}. See the definition in clinic.py:

r('z#', zeroes=True, accept={robuffer, str, NoneType})

_testcapi.dict_getitemstringref
obj: object
value: object
attr_name: str(accept={robuffer}, zeroes=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it is possible to just use the legacy converter:

Suggested change
attr_name: str(accept={robuffer}, zeroes=True)
attr_name: 'z#'

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@serhiy-storchaka
Copy link
Member

It significantly reduces readability to me.

It significantly increases the number of lines in Modules/_testcapi/dict.c:

 Modules/_testcapi/dict.c | 412 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------
 1 file changed, 291 insertions(+), 121 deletions(-)

And this is not counting the large amount of code added to another file.

I have a limited field of vision and can't see anything beyond a limited number of lines of code. Before that, test functions were compact. After these changes, they will exceed my limit. And if I need to understand what exactly the function does, I have to look for the corresponding code in the generated file and then go back to the previous file, but when I look from the file I lose the context and I have to reread each line on the screen again to find the right place.

These changes are not friendly to the visually impaired.

@jamie2779
Copy link
Author

@erlend-aasland @corona10 I have made the requested changes; Please Take Another Look!

@erlend-aasland
Copy link
Contributor

I think Serhiy's opinion should be taken into account. Converting _testcapi to Argument Clinic is not of importance.

@ambv
Copy link
Contributor

ambv commented Aug 11, 2023

Closing and re-opening to retrigger CLA checks. Sorry for the noise.

@ambv ambv closed this Aug 11, 2023
@ambv ambv reopened this Aug 11, 2023
@cpython-cla-bot
Copy link

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@corona10
Copy link
Member

close via #104469 (comment)

@corona10 corona10 closed this Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants