GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-87390: Fix starred tuple equality and pickling by mrahtz · Pull Request #92249 · python/cpython Conversation
|
|
I think this is worth a NEWS entry; it's been a while since we put the rest of this code into main. I'll review the PR now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm a little unhappy about making unpacked a public argument to the constructor, but I'm not sure how else we'd get pickling to work.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]>
I've added a NEWS entry for this specific change, but just to double check - were you thinking of this specific change, or the rest of the PEP 646-related changes we made to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Just for this change (the PR title would be good as a NEWS entry too). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "must be a bool (since it's a flag controlling " | ||
| "whether the alias is unpacked)"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| "must be a bool (since it's a flag controlling " | |
| "whether the alias is unpacked)"); | |
| "must be a bool"); |
We don't need the explanation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Great work! We're pretty close.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PyObject *starred = PyBool_FromLong(alias->starred); | ||
| PyObject *value = Py_BuildValue("O(OOO)", Py_TYPE(alias), | ||
| alias->origin, alias->args, starred); | ||
| // Avoid double increment of reference count on Py_True/Py_False - once from | ||
| // PyBool_FromLong, and once from Py_BuildValue. | ||
| Py_CLEAR(starred); | ||
| return value; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How about:
| PyObject *starred = PyBool_FromLong(alias->starred); | |
| PyObject *value = Py_BuildValue("O(OOO)", Py_TYPE(alias), | |
| alias->origin, alias->args, starred); | |
| // Avoid double increment of reference count on Py_True/Py_False - once from | |
| // PyBool_FromLong, and once from Py_BuildValue. | |
| Py_CLEAR(starred); | |
| return value; | |
| PyObject *starred = alias->starred ? Py_True : Py_False; | |
| return Py_BuildValue("O(OOO)", Py_TYPE(alias), | |
| alias->origin, alias->args, starred); | |
BTW, if you don't want to use the code above, you can avoid the double incref by using the format string O(OON). N doesn't incref. https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return NULL; | ||
| } | ||
| if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2)) { | ||
| if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 3)) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please update the creation signature in the docs https://docs.python.org/3/library/types.html#types.GenericAlias.
Also, this doesn't break backwards compatibility right? IIUC, the two-argument form will still work.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PyObject *origin = PyTuple_GET_ITEM(args, 0); | ||
| PyObject *arguments = PyTuple_GET_ITEM(args, 1); | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This code has gotten complex enough that I recommend using https://docs.python.org/3/c-api/arg.html#c.PyArg_ParseTuple or https://docs.python.org/3/c-api/arg.html#c.PyArg_UnpackTuple instead to parse our arguments for us.
The format value list is on that page. But off the top of my head, it should be OO|O:GenericAlias. Then you keep your bool checking/error raising code below.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Argument clinic can also be used here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "whether the alias is unpacked)"); | ||
| return NULL; | ||
| } | ||
| starred = PyLong_AsLong(py_starred); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised you don't need to cast to (bool) here (or maybe it's implicit, I don't remember how C treats this).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Azure pipelines patcheck fail is unrelated, I will fix it on main. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Nevermind, it seems that 65f88a6 fixed the whitespace issues, so this just needs updating from main. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I do not like an idea about extending GenericAlias() with the third parameter. It is a public API.
I'll provide an alternate PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
See #92337. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looks like this can be closed since the alternative was already merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.