Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-133783: Fix __replace__ on AST nodes for optional attributes#133797
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix bug with applying:func:`copy.replace` to:mod:`ast` objects. Attributes | ||
that default to ``None`` were incorrectly treated as required for manually | ||
created AST nodes. |
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1244,6 +1244,32 @@ def visitModule(self, mod): | ||
Py_DECREF(unused); | ||
} | ||
} | ||
// Discard fields from 'expecting' that default to None | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
PyObject *field_types = NULL; | ||
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), | ||
&_Py_ID(_field_types), | ||
&field_types) < 0) | ||
{ | ||
Py_DECREF(expecting); | ||
return -1; | ||
} | ||
if (field_types != NULL) { | ||
Py_ssize_t pos = 0; | ||
PyObject *field_name, *field_type; | ||
while (PyDict_Next(field_types, &pos, &field_name, &field_type)) { | ||
if (_PyUnion_Check(field_type)) { | ||
// optional field | ||
if (PySet_Discard(expecting, field_name) < 0) { | ||
Py_DECREF(expecting); | ||
Py_DECREF(field_types); | ||
return -1; | ||
} | ||
} | ||
} | ||
Py_DECREF(field_types); | ||
} | ||
// Now 'expecting' contains the fields or attributes | ||
// that would not be filled inside ast_type_replace(). | ||
Py_ssize_t m = PySet_GET_SIZE(expecting); | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.