-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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-112068: C API: Add support of nullable arguments in PyArg_Parse (suffix) #121303
base: main
Are you sure you want to change the base?
gh-112068: C API: Add support of nullable arguments in PyArg_Parse (suffix) #121303
Conversation
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.
I'm really sorry that you needed to implement the suffix just for me to actually understand that it's probably harder to maintain and to extend compared to the prefix case.
The only reason why I would advocate for the suffix is more because of its use in other languages but maybe I shouldn't have kept that argument at the top of my list and should have rather go for a more simple implementation (for instance in TypeScript, you write function sumTwoMaybeThree(x: number, y: number, z?: number): number
and in other languages as I said you have the ?.
operator.
In addition, since (...)?
is not yet implemented, I assume that it would be even more complex since you need to open / close contexts and after all that, you still need to parse that ?
. However ?(...)
would be easier to implement I think since you could add the flag beforehand and process (...)
normally.
By the way, is there a reason why we have a huge switch instead of some separate functions like in _testcapi/getargs.c
? is it only for efficiency purposes and to reduce function calls (though those could be probably inlined)?
@@ -616,6 +624,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, | |||
char *msgbuf, size_t bufsize, freelist_t *freelist) | |||
{ | |||
#define RETURN_ERR_OCCURRED return msgbuf | |||
#define HANDLE_NULLABLE \ |
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.
I know understand why the implementation is more complex. You essentially need to add that macro after every flag that is parsed instead of handling it as if it were a regular character.
In case of multicharacter format unit you need to reorganize the code and add new code at all right places. This is actually simpler than I thought, because the same macros can be used in all cases (except For |
I managed to implement |
This is a variant of #121187, but with suffix instead of prefix.
i?
instead of?i
.