Skip to content

Commit 661ea26

Browse files
committed
Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
1 parent bd6f4fb commit 661ea26

16 files changed

+186
-144
lines changed

Lib/test/output/test_extcall

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ test_extcall
99
(1, 2, 3) {'b': 5, 'a': 4}
1010
(1, 2, 3, 4, 5) {'b': 7, 'a': 6}
1111
(1, 2, 3, 6, 7) {'y': 5, 'b': 9, 'x': 4, 'a': 8}
12-
TypeError: not enough arguments; expected 1, got 0
13-
TypeError: not enough arguments; expected 1, got 0
14-
TypeError: not enough arguments; expected 1, got 0
12+
TypeError: not enough arguments to g(); expected 1, got 0
13+
TypeError: not enough arguments to g(); expected 1, got 0
14+
TypeError: not enough arguments to g(); expected 1, got 0
1515
1 () {}
1616
1 (2,) {}
1717
1 (2, 3) {}
@@ -20,10 +20,10 @@ TypeError: not enough arguments; expected 1, got 0
2020
1 () {'d': 4, 'b': 2, 'c': 3, 'a': 1}
2121
{'b': 2, 'c': 3, 'a': 1}
2222
{'b': 2, 'c': 3, 'a': 1}
23-
keyword parameter redefined: x
24-
keyword parameter redefined: b
23+
keyword parameter 'x' redefined in call to g()
24+
keyword parameter 'b' redefined in function call
2525
keywords must be strings
26-
unexpected keyword argument: e
26+
h() got an unexpected keyword argument 'e'
2727
* argument must be a sequence
2828
** argument must be a dictionary
2929
3 512 1

Modules/dbmmodule.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
140140
if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) {
141141
dbm_clearerr(dp->di_dbm);
142142
PyErr_SetString(DbmError,
143-
"Cannot add item to database");
143+
"cannot add item to database");
144144
return -1;
145145
}
146146
}
@@ -255,7 +255,7 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
255255
val.dsize = PyString_GET_SIZE(defvalue);
256256
if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) {
257257
dbm_clearerr(dp->di_dbm);
258-
PyErr_SetString(DbmError, "Cannot add item to database");
258+
PyErr_SetString(DbmError, "cannot add item to database");
259259
return NULL;
260260
}
261261
return defvalue;
@@ -325,7 +325,7 @@ dbmopen(PyObject *self, PyObject *args)
325325
iflags = O_RDWR|O_CREAT|O_TRUNC;
326326
else {
327327
PyErr_SetString(DbmError,
328-
"Flags should be one of 'r', 'w', 'c' or 'n'");
328+
"arg 2 to open should be 'r', 'w', 'c', or 'n'");
329329
return NULL;
330330
}
331331
return newdbmobject(name, iflags, mode);

Modules/parsermodule.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ parser_do_parse(PyObject *args, PyObject *kw, char *argspec, int type)
508508
if (n != 0)
509509
res = parser_newastobject(n, type);
510510
else
511-
err_string("Could not parse string.");
511+
err_string("could not parse string");
512512
}
513513
return (res);
514514
}
@@ -611,14 +611,14 @@ parser_tuple2ast(PyAST_Object *self, PyObject *args, PyObject *kw)
611611
else {
612612
/* This is a fragment, at best. */
613613
PyNode_Free(tree);
614-
err_string("Parse tree does not use a valid start symbol.");
614+
err_string("parse tree does not use a valid start symbol");
615615
}
616616
}
617617
/* Make sure we throw an exception on all errors. We should never
618618
* get this, but we'd do well to be sure something is done.
619619
*/
620620
if ((ast == 0) && !PyErr_Occurred())
621-
err_string("Unspecified ast error occurred.");
621+
err_string("unspecified AST error occurred");
622622

623623
return (ast);
624624
}
@@ -670,16 +670,16 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
670670
PyObject *temp;
671671

672672
if ((len != 2) && (len != 3)) {
673-
err_string("Terminal nodes must have 2 or 3 entries.");
673+
err_string("terminal nodes must have 2 or 3 entries");
674674
return 0;
675675
}
676676
temp = PySequence_GetItem(elem, 1);
677677
if (temp == NULL)
678678
return 0;
679679
if (!PyString_Check(temp)) {
680680
PyErr_Format(parser_error,
681-
"Second item in terminal node must be a string,"
682-
" found %s.",
681+
"second item in terminal node must be a string,"
682+
" found %s",
683683
((PyTypeObject*)PyObject_Type(temp))->tp_name);
684684
Py_DECREF(temp);
685685
return 0;
@@ -691,8 +691,8 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
691691
*line_num = PyInt_AS_LONG(o);
692692
else {
693693
PyErr_Format(parser_error,
694-
"Third item in terminal node must be an"
695-
" integer, found %s.",
694+
"third item in terminal node must be an"
695+
" integer, found %s",
696696
((PyTypeObject*)PyObject_Type(temp))->tp_name);
697697
Py_DECREF(o);
698698
Py_DECREF(temp);
@@ -713,7 +713,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
713713
* Throw an exception.
714714
*/
715715
PyErr_SetObject(parser_error,
716-
Py_BuildValue("os", elem, "Unknown node type."));
716+
Py_BuildValue("os", elem, "unknown node type."));
717717
Py_XDECREF(elem);
718718
return (0);
719719
}
@@ -1566,7 +1566,7 @@ validate_dotted_as_name(node *tree)
15661566
&& validate_name(CHILD(tree, 2), NULL));
15671567
else {
15681568
res = 0;
1569-
err_string("Illegal number of children for dotted_as_name.");
1569+
err_string("illegal number of children for dotted_as_name");
15701570
}
15711571
}
15721572
return res;
@@ -1655,7 +1655,7 @@ validate_exec_stmt(node *tree)
16551655
&& validate_expr(CHILD(tree, 1)));
16561656

16571657
if (!res && !PyErr_Occurred())
1658-
err_string("Illegal exec statement.");
1658+
err_string("illegal exec statement");
16591659
if (res && (nch > 2))
16601660
res = (validate_name(CHILD(tree, 2), "in")
16611661
&& validate_test(CHILD(tree, 3)));
@@ -1682,7 +1682,7 @@ validate_assert_stmt(node *tree)
16821682
&& validate_test(CHILD(tree, 1)));
16831683

16841684
if (!res && !PyErr_Occurred())
1685-
err_string("Illegal assert statement.");
1685+
err_string("illegal assert statement");
16861686
if (res && (nch > 2))
16871687
res = (validate_comma(CHILD(tree, 2))
16881688
&& validate_test(CHILD(tree, 3)));
@@ -1778,7 +1778,7 @@ validate_try(node *tree)
17781778
res = ((strcmp(STR(CHILD(tree, pos)), "except") == 0)
17791779
|| (strcmp(STR(CHILD(tree, pos)), "else") == 0));
17801780
if (!res)
1781-
err_string("Illegal trailing triple in try statement.");
1781+
err_string("illegal trailing triple in try statement");
17821782
}
17831783
else if (nch == (pos + 6)) {
17841784
res = (validate_name(CHILD(tree, pos), "except")
@@ -1912,11 +1912,11 @@ validate_comp_op(node *tree)
19121912
|| (strcmp(STR(tree), "is") == 0));
19131913
if (!res) {
19141914
PyErr_Format(parser_error,
1915-
"Illegal operator: '%s'.", STR(tree));
1915+
"illegal operator '%s'", STR(tree));
19161916
}
19171917
break;
19181918
default:
1919-
err_string("Illegal comparison operator type.");
1919+
err_string("illegal comparison operator type");
19201920
break;
19211921
}
19221922
}
@@ -1928,7 +1928,7 @@ validate_comp_op(node *tree)
19281928
|| ((strcmp(STR(CHILD(tree, 0)), "not") == 0)
19291929
&& (strcmp(STR(CHILD(tree, 1)), "in") == 0))));
19301930
if (!res && !PyErr_Occurred())
1931-
err_string("Unknown comparison operator.");
1931+
err_string("unknown comparison operator");
19321932
}
19331933
return (res);
19341934
}
@@ -2075,7 +2075,7 @@ validate_power(node *tree)
20752075
res = validate_trailer(CHILD(tree, pos++));
20762076
if (res && (pos < nch)) {
20772077
if (!is_even(nch - pos)) {
2078-
err_string("Illegal number of nodes for 'power'.");
2078+
err_string("illegal number of nodes for 'power'");
20792079
return (0);
20802080
}
20812081
for ( ; res && (pos < (nch - 1)); pos += 2)
@@ -2532,7 +2532,7 @@ validate_node(node *tree)
25322532
if (res)
25332533
next = CHILD(tree, 0);
25342534
else if (nch == 1)
2535-
err_string("Illegal flow_stmt type.");
2535+
err_string("illegal flow_stmt type");
25362536
break;
25372537
/*
25382538
* Compound statements.
@@ -2654,7 +2654,7 @@ validate_node(node *tree)
26542654

26552655
default:
26562656
/* Hopefully never reached! */
2657-
err_string("Unrecogniged node type.");
2657+
err_string("unrecognized node type");
26582658
res = 0;
26592659
break;
26602660
}
@@ -2670,7 +2670,7 @@ validate_expr_tree(node *tree)
26702670
int res = validate_eval_input(tree);
26712671

26722672
if (!res && !PyErr_Occurred())
2673-
err_string("Could not validate expression tuple.");
2673+
err_string("could not validate expression tuple");
26742674

26752675
return (res);
26762676
}
@@ -2698,7 +2698,7 @@ validate_file_input(node *tree)
26982698
* this, we have some debugging to do.
26992699
*/
27002700
if (!res && !PyErr_Occurred())
2701-
err_string("VALIDATION FAILURE: report this to the maintainer!.");
2701+
err_string("VALIDATION FAILURE: report this to the maintainer!");
27022702

27032703
return (res);
27042704
}

0 commit comments

Comments
 (0)