|
4 | 4 | #include "symtable.h" |
5 | 5 | #include "structmember.h" |
6 | 6 |
|
7 | | -/* two error strings used for warnings */ |
| 7 | +/* error strings used for warnings */ |
8 | 8 | #define GLOBAL_AFTER_ASSIGN \ |
9 | 9 | "name '%.400s' is assigned to before global declaration" |
10 | 10 |
|
11 | 11 | #define GLOBAL_AFTER_USE \ |
12 | 12 | "name '%.400s' is used prior to global declaration" |
13 | 13 |
|
| 14 | +#define IMPORT_STAR_WARNING "import * only allowed at module level" |
| 15 | + |
| 16 | + |
14 | 17 | PySTEntryObject * |
15 | 18 | PySTEntry_New(struct symtable *st, identifier name, _Py_block_ty block, |
16 | 19 | void *key, int lineno) |
@@ -152,7 +155,7 @@ PyTypeObject PySTEntry_Type = { |
152 | 155 | }; |
153 | 156 |
|
154 | 157 | static int symtable_analyze(struct symtable *st); |
155 | | -static int symtable_warn(struct symtable *st, char *msg); |
| 158 | +static int symtable_warn(struct symtable *st, char *msg, int lineno); |
156 | 159 | static int symtable_enter_block(struct symtable *st, identifier name, |
157 | 160 | _Py_block_ty block, void *ast, int lineno); |
158 | 161 | static int symtable_exit_block(struct symtable *st, void *ast); |
@@ -686,10 +689,10 @@ symtable_analyze(struct symtable *st) |
686 | 689 |
|
687 | 690 |
|
688 | 691 | static int |
689 | | -symtable_warn(struct symtable *st, char *msg) |
| 692 | +symtable_warn(struct symtable *st, char *msg, int lineno) |
690 | 693 | { |
691 | 694 | if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename, |
692 | | - st->st_cur->ste_lineno, NULL, NULL) < 0) { |
| 695 | + lineno, NULL, NULL) < 0) { |
693 | 696 | if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) { |
694 | 697 | PyErr_SetString(PyExc_SyntaxError, msg); |
695 | 698 | PyErr_SyntaxLocation(st->st_filename, |
@@ -1028,7 +1031,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) |
1028 | 1031 | PyOS_snprintf(buf, sizeof(buf), |
1029 | 1032 | GLOBAL_AFTER_USE, |
1030 | 1033 | c_name); |
1031 | | - if (!symtable_warn(st, buf)) |
| 1034 | + if (!symtable_warn(st, buf, s->lineno)) |
1032 | 1035 | return 0; |
1033 | 1036 | } |
1034 | 1037 | if (!symtable_add_def(st, name, DEF_GLOBAL)) |
@@ -1277,8 +1280,8 @@ symtable_visit_alias(struct symtable *st, alias_ty a) |
1277 | 1280 | } |
1278 | 1281 | else { |
1279 | 1282 | if (st->st_cur->ste_type != ModuleBlock) { |
1280 | | - if (!symtable_warn(st, |
1281 | | - "import * only allowed at module level")) { |
| 1283 | + int lineno = st->st_cur->ste_lineno; |
| 1284 | + if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) { |
1282 | 1285 | Py_DECREF(store_name); |
1283 | 1286 | return 0; |
1284 | 1287 | } |
|
0 commit comments