Skip to content

GH-132775: Fix argument parsing for _interpqueues.put() #137686

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Aug 12, 2025

@@ -1603,7 +1603,7 @@ queuesmod_put(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *obj;
int unboundarg = -1;
int fallbackarg = -1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|ii$p:put", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|ii:put", kwlist,
Copy link
Member

Choose a reason for hiding this comment

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

I think that this is the correct solution:

Suggested change
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|ii:put", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|i$p:put", kwlist,

Please add tests with the fallback argument equal to None, -1, 2**1000 -- there should be different behavior for patched and unpatched code. Also, fallback is now keyword-only. And passing unsupported keyword argument could crash the old code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with 'i' because that's what .create() uses, but I'm now not sure which is more correct. @ericsnowcurrently?

Copy link
Member

Choose a reason for hiding this comment

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

#134440 removed fmt ("i") and added keyword-only boolean fallback ("p"). We usually make booleans keyword-only.

fallback has only three state -- _PyXIDATA_XIDATA_ONLY (0), _PyXIDATA_FULL_FALLBACK (1), and default negative value used to distinguish "no argument" from passed value. Other positive values are errors.

If it was also added in other functions, it most likely should be keyword-only boolean too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've done as you suggest. Note the changes I had to make to .create(), though.

It would be good to get this in to 3.14rc2 (now this Thu). Feel free to take over the branch.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Unfortunately, queues.put() is never called with the fallback argument, so we do not have examples of non-default values. queues.create() is only called with the default value -1. Maybe @ericsnowcurrently planned to add named constants for fallback, as for unbound. Or he started with integers and planned to make it boolean. Only he can answer these questions, we do not have enough information.

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.

2 participants