Skip to content

Commit 980aa20

Browse files
committed
Address review
1 parent f64b60b commit 980aa20

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ def cleanup():
9494

9595
del ast.AST._fields
9696

97-
msg = 'AST has no fields'
97+
msg = "type object 'ast.AST' has no attribute '_fields'"
9898
# Both examples used to crash:
99-
with self.assertRaisesRegex(TypeError, msg):
99+
with self.assertRaisesRegex(AttributeError, msg):
100100
ast.AST(arg1=123)
101-
with self.assertRaisesRegex(TypeError, msg):
101+
with self.assertRaisesRegex(AttributeError, msg):
102102
ast.AST()
103103

104104
def test_AST_garbage_collection(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix a crash in :mod:`ast` when ``_fields`` attribute is deleted.
1+
Fix a crash in :mod:`ast` when the :attr:`ast.AST._fields` attribute is deleted.

Parser/asdl_c.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,13 +884,9 @@ def visitModule(self, mod):
884884
Py_ssize_t i, numfields = 0;
885885
int res = -1;
886886
PyObject *key, *value, *fields, *attributes = NULL, *remaining_fields = NULL;
887-
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
888-
goto cleanup;
889-
}
887+
888+
fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields);
890889
if (fields == NULL) {
891-
PyErr_Format(PyExc_TypeError,
892-
"%.400s has no fields",
893-
_PyType_Name(Py_TYPE(self)));
894890
goto cleanup;
895891
}
896892

Python/Python-ast.c

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)