Skip to content

Commit fcb20ae

Browse files
committed
Make error messages actually work
1 parent 2c278ca commit fcb20ae

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ struct _Py_global_strings {
482482
STRUCT_FOR_ID(kw2)
483483
STRUCT_FOR_ID(lambda)
484484
STRUCT_FOR_ID(last)
485+
STRUCT_FOR_ID(last_exc)
485486
STRUCT_FOR_ID(last_node)
486487
STRUCT_FOR_ID(last_traceback)
487488
STRUCT_FOR_ID(last_type)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

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

Lib/typing.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ def _collect_parameters(args):
260260
if t.__default__ is not None:
261261
seen_default = True
262262
elif seen_default:
263-
raise TypeError("TypeVarLike without a default follows one with a default")
263+
raise TypeError(
264+
f"TypeVarLike {t!r} without a default follows one with a default"
265+
)
264266

265267
parameters.append(t)
266268
else:
@@ -269,7 +271,9 @@ def _collect_parameters(args):
269271
if x.__default__ is not None:
270272
seen_default = True
271273
elif seen_default:
272-
raise TypeError("TypeVarLike without a default follows one with a default")
274+
raise TypeError(
275+
f"TypeVarLike {t!r} without a default follows one with a default"
276+
)
273277

274278
parameters.append(x)
275279
return tuple(parameters)

Objects/genericaliasobject.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ _Py_make_parameters(PyObject *args)
227227
Py_DECREF(parameters);
228228
return NULL;
229229
}
230-
printf("Here\n");
231230
if (subst) {
232-
printf("subst checking contains\n");
233-
PyObject_Print(t, stdout, 0);
234-
PyObject_Print(parameters, stdout, 0);
235231
PyObject *default_;
236232
bool does_not_contain = tuple_index(parameters, nargs, t) == -1;
237233
if (does_not_contain) {
@@ -240,13 +236,15 @@ _Py_make_parameters(PyObject *args)
240236
Py_DECREF(subst);
241237
return NULL;
242238
}
243-
PyObject_Print(default_, stdout, 0);
244-
if (default_ && !!Py_IsNone(default_)) {
239+
if (!Py_IsNone(default_)) {
245240
seen_default = true;
246241
} else if (seen_default) {
247-
PyErr_Format(PyExc_TypeError, "TypeVarLike without a default follows one with a default");
242+
return PyErr_Format(
243+
PyExc_TypeError,
244+
"type parameter %R without a default follows one with a default",
245+
t
246+
);
248247
}
249-
printf("\n%d seen default\n", seen_default);
250248
}
251249

252250
iparam += tuple_add(parameters, iparam, t);
@@ -274,19 +272,21 @@ _Py_make_parameters(PyObject *args)
274272
PyObject *default_;
275273
PyObject *t2 = PyTuple_GET_ITEM(subparams, j);
276274

277-
bool does_not_contain = tuple_index(parameters, nargs, t) == -1;
275+
bool does_not_contain = tuple_index(parameters, nargs, t2) == -1;
278276
if (does_not_contain) {
279277
if (_PyObject_LookupAttr(t2, &_Py_ID(__default__), &default_) < 0) {
280278
Py_DECREF(default_);
281279
Py_DECREF(subst);
282280
return NULL;
283281
}
284-
PyObject_Print(default_, stdout, 0);
285-
printf("\n%d seen default\n", seen_default);
286-
if (default_ && !!Py_IsNone(default_)) {
282+
if (default_ && !Py_IsNone(default_)) {
287283
seen_default = true;
288284
} else if (seen_default) {
289-
PyErr_Format(PyExc_TypeError, "TypeVarLike without a default follows one with a default");
285+
return PyErr_Format(
286+
PyExc_TypeError,
287+
"type parameter %R without a default follows one with a default",
288+
t2
289+
);
290290
}
291291
}
292292
iparam += tuple_add(parameters, iparam, t2);

0 commit comments

Comments
 (0)