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

Updated ImagePath tolist() default #7138

Merged
merged 2 commits into from
May 5, 2023

Conversation

radarhere
Copy link
Member

ImagePath.Path.tolist() is a C function that we have exposed in our public Python API. It has an argument flat that it uses like so -

Pillow/src/path.c

Lines 431 to 440 in b073a89

path_tolist(PyPathObject *self, PyObject *args) {
PyObject *list;
Py_ssize_t i;
int flat = 0;
if (!PyArg_ParseTuple(args, "|i:tolist", &flat)) {
return NULL;
}
if (flat) {

Looking at the documentation for ImagePath.Path.tolist(), https://pillow.readthedocs.io/en/stable/reference/ImagePath.html#PIL.ImagePath.PIL.ImagePath.Path.tolist, flat is documented as

flat – By default, this function returns a list of 2-tuples [(x, y), …]. If this argument is True, it returns a flat list [x, y, …] instead.

Ok, so flat is a boolean. That's how it should be thought of, and how it is used.

Except the documentation at that link also the default for flat as 0, which could cause a brief moment of confusion as to why the default is a different type.

Screenshot 2023-05-05 at 6 18 18 pm

The reason isn't not False would be because the code is in C, not Python, but I think it would be clearer if we described our Python API as having a default of False.

@radarhere radarhere changed the title Updated ImagePath tolist() default in documentation Updated ImagePath tolist() default May 5, 2023
@hugovk hugovk merged commit 97c0e29 into python-pillow:main May 5, 2023
@hugovk
Copy link
Member

hugovk commented May 5, 2023

I added the documentation label, but then saw you added and removed it too! Feel free to remove it again if you like :)

@radarhere radarhere deleted the imagepath_default branch May 5, 2023 09:49
@radarhere
Copy link
Member Author

It was initially documentation only, but then I technically changed a test too in the second commit, so... whatever works.

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