@@ -554,8 +554,8 @@ def typeCheck(self, name):
554554 self .emit ("return 1;" , 2 )
555555 self .emit ("}" , 1 )
556556 self .emit ("if (!isinstance && field != NULL) {" , 1 )
557- error = "field '%%s' was expecting node of type '%s', got '%%s '" % name
558- self .emit ("PyErr_Format(PyExc_TypeError, \" %s\" , field, _PyType_Name(Py_TYPE( obj)) );" % error , 2 , reflow = False )
557+ error = "field '%%s' was expecting node of type '%s', got '%%T '" % name
558+ self .emit ("PyErr_Format(PyExc_TypeError, \" %s\" , field, obj);" % error , 2 , reflow = False )
559559 self .emit ("return 1;" , 2 )
560560 self .emit ("}" , 1 )
561561
@@ -692,7 +692,7 @@ def visitField(self, field, name, sum=None, prod=None, depth=0):
692692 self .emit ("Py_ssize_t i;" , depth + 1 )
693693 self .emit ("if (!PyList_Check(tmp)) {" , depth + 1 )
694694 self .emit ("PyErr_Format(PyExc_TypeError, \" %s field \\ \" %s\\ \" must "
695- "be a list, not a %%.200s \" , _PyType_Name(Py_TYPE( tmp)) );" %
695+ "be a list, not a %%T \" , tmp);" %
696696 (name , field .name ),
697697 depth + 2 , reflow = False )
698698 self .emit ("goto failed;" , depth + 2 )
@@ -991,10 +991,9 @@ def visitModule(self, mod):
991991
992992 res = 0; /* if no error occurs, this stays 0 to the end */
993993 if (numfields < PyTuple_GET_SIZE(args)) {
994- PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
994+ PyErr_Format(PyExc_TypeError, "%T constructor takes at most "
995995 "%zd positional argument%s",
996- _PyType_Name(Py_TYPE(self)),
997- numfields, numfields == 1 ? "" : "s");
996+ self, numfields, numfields == 1 ? "" : "s");
998997 res = -1;
999998 goto cleanup;
1000999 }
@@ -1748,7 +1747,7 @@ def visitModule(self, mod):
17481747static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
17491748{
17501749 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1751- PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string object", field);
1750+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string object, got %T ", field, obj );
17521751 return -1;
17531752 }
17541753 return obj2ast_object(state, obj, out, field, arena);
@@ -1757,7 +1756,7 @@ def visitModule(self, mod):
17571756static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
17581757{
17591758 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1760- PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string or bytes object", field);
1759+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string or bytes object, got %T ", field, obj );
17611760 return -1;
17621761 }
17631762 return obj2ast_object(state, obj, out, field, arena);
@@ -2144,8 +2143,8 @@ class PartingShots(StaticVisitor):
21442143 return -1;
21452144 }
21462145 if (!isinstance) {
2147- PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s ",
2148- req_name[mode], _PyType_Name(Py_TYPE( ast)) );
2146+ PyErr_Format(PyExc_TypeError, "expected %s node, got %T ",
2147+ req_name[mode], ast);
21492148 return -1;
21502149 }
21512150 return 0;
0 commit comments