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

bpo-40408: Fix support of nested type variables in GenericAlias. #19836

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented May 1, 2020

@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label May 1, 2020
@serhiy-storchaka
Copy link
Member Author

@gvanrossum please take a look at this.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LG, just style suggestions.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Some more suggestions. Thanks for explaining LookupAttrId, I had forgotten its API. :-)

@@ -263,13 +308,19 @@ ga_getitem(PyObject *self, PyObject *item)
}
int is_tuple = PyTuple_Check(item);
Py_ssize_t nitem = is_tuple ? PyTuple_GET_SIZE(item) : 1;
Copy link
Member

Choose a reason for hiding this comment

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

I'd rename nitem to nitems.

Comment on lines 250 to 251
/* If obj is a generic alias, substitute type variables params
with substitutions argitems. */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/* If obj is a generic alias, substitute type variables params
with substitutions argitems. */
/* If obj is a generic alias, substitute type variables params
with substitutions argitems. For example, if obj is list[T],
params is (T, S), and argitems is (str, int), return list[str].
If obj doesn't have a __parameters__ attribute or that's not
a non-empty tuple, return obj, INCREF'ed. */

Py_INCREF(arg);
PyTuple_SET_ITEM(subargs, i, arg);
}
obj = PyObject_GetItem(obj, subargs);
Copy link
Member

Choose a reason for hiding this comment

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

Since this is the operation we've been preparing for, I'd set it apart with a blank line before and after.

return NULL;
}
if (subparams && PyTuple_Check(subparams)) {
Py_ssize_t nparams = PyTuple_GET_SIZE(params);
Copy link
Member

Choose a reason for hiding this comment

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

This could be moved into the if (nsubargs != 0) { block below.

(Also the logic would be slightly simpler if the check for subparams being non-empty was part of the if (subparams && PyTuple_Check(subparams)) { check above.)

else {
Py_INCREF(arg);
}
Py_XDECREF(subparams);
}
PyTuple_SET_ITEM(newargs, iarg, arg);
}
Copy link
Member

Choose a reason for hiding this comment

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

Comment for the next line: (again) since it is the main event we've been working up to, offset it with a blank line before and after.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Perfect!

@serhiy-storchaka
Copy link
Member Author

Thank you very much for your review!

@serhiy-storchaka serhiy-storchaka merged commit 41a6458 into python:master May 4, 2020
@serhiy-storchaka serhiy-storchaka deleted the generic-alias-nested-typed-vars branch May 4, 2020 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants