-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
bpo-40408: Fix support of nested type variables in GenericAlias. #19836
Conversation
@gvanrossum please take a look at this. |
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.
LG, just style suggestions.
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.
Some more suggestions. Thanks for explaining LookupAttrId, I had forgotten its API. :-)
Objects/genericaliasobject.c
Outdated
@@ -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; |
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'd rename nitem
to nitems
.
Objects/genericaliasobject.c
Outdated
/* If obj is a generic alias, substitute type variables params | ||
with substitutions argitems. */ |
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.
/* 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. */ |
Objects/genericaliasobject.c
Outdated
Py_INCREF(arg); | ||
PyTuple_SET_ITEM(subargs, i, arg); | ||
} | ||
obj = PyObject_GetItem(obj, subargs); |
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.
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); |
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.
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); | ||
} |
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.
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.
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.
Perfect!
Thank you very much for your review! |
https://bugs.python.org/issue40408