-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Conversation
jamie2779
commented
Aug 11, 2023
•
edited by bedevere-bot
Loading
edited by bedevere-bot
- Issue: Improve the readability and maintainability of test_capi using the AC #104469
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Modules/_testcapi/dict.c
Outdated
_testcapi.dict_getitemstringref | ||
obj: object | ||
value: object | ||
attr_name: str(accept={robuffer}, zeroes=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like str(accept={str, NoneType}, zeroes=True)
according to https://docs.python.org/3/howto/clinic.html?highlight=clinic#how-to-use-real-argument-clinic-converters-instead-of-legacy-converters
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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:
cpython/Tools/clinic/clinic.py
Line 3927 in 23a6db9
r('z#', zeroes=True, accept={robuffer, str, NoneType}) |
There was a problem hiding this comment.
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:
attr_name: str(accept={robuffer}, zeroes=True) | |
attr_name: 'z#' |
Modules/_testcapi/dict.c
Outdated
_testcapi.dict_getitemref | ||
obj: object | ||
attr_name: object | ||
value: object |
There was a problem hiding this comment.
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
.
Modules/_testcapi/dict.c
Outdated
/*[clinic input] | ||
_testcapi.dict_getitemstringref | ||
obj: object | ||
value: object |
There was a problem hiding this comment.
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.
Modules/_testcapi/dict.c
Outdated
value: object | ||
key: str(accept={robuffer}, zeroes=True) |
There was a problem hiding this comment.
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
.
Modules/_testcapi/dict.c
Outdated
_testcapi.dict_getitemstringref | ||
obj: object | ||
value: object | ||
attr_name: str(accept={robuffer}, zeroes=True) |
There was a problem hiding this comment.
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:
cpython/Tools/clinic/clinic.py
Line 3927 in 23a6db9
r('z#', zeroes=True, accept={robuffer, str, NoneType}) |
Modules/_testcapi/dict.c
Outdated
_testcapi.dict_getitemstringref | ||
obj: object | ||
value: object | ||
attr_name: str(accept={robuffer}, zeroes=True) |
There was a problem hiding this comment.
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:
attr_name: str(accept={robuffer}, zeroes=True) | |
attr_name: 'z#' |
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 |
It significantly reduces readability to me. It significantly increases the number of lines in
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. |
@erlend-aasland @corona10 I have made the requested changes; Please Take Another Look! |
I think Serhiy's opinion should be taken into account. Converting _testcapi to Argument Clinic is not of importance. |
Closing and re-opening to retrigger CLA checks. Sorry for the noise. |
The following commit authors need to sign the Contributor License Agreement: |
close via #104469 (comment) |