8000 compiler_import, compiler_import_as return SUCCESS/ERROR · python/cpython@6966b26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6966b26

Browse files
committed
compiler_import, compiler_import_as return SUCCESS/ERROR
1 parent 73d8b72 commit 6966b26

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

Python/compile.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,33 +4000,36 @@ compiler_import_as(struct compiler *c, location loc,
40004000
*/
40014001
Py_ssize_t len = PyUnicode_GET_LENGTH(name);
40024002
Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0, len, 1);
4003-
if (dot == -2)
4004-
return 0;
4003+
if (dot == -2) {
4004+
return ERROR;
4005+
}
40054006
if (dot != -1) {
40064007
/* Consume the base module name to get the first attribute */
40074008
while (1) {
40084009
Py_ssize_t pos = dot + 1;
40094010
PyObject *attr;
40104011
dot = PyUnicode_FindChar(name, '.', pos, len, 1);
4011-
if (dot == -2)
4012-
return 0;
4012+
if (dot == -2) {
4013+
return ERROR;
4014+
}
40134015
attr = PyUnicode_Substring(name, pos, (dot != -1) ? dot : len);
4014-
if (!attr)
4015-
return 0;
4016-
_ADDOP_N(c, loc, IMPORT_FROM, attr, names);
4016+
if (!attr) {
4017+
return ERROR;
4018+
}
4019+
ADDOP_N(c, loc, IMPORT_FROM, attr, names);
40174020
if (dot == -1) {
40184021
break;
40194022
}
4020-
_ADDOP_I(c, loc, SWAP, 2);
4021-
_ADDOP(c, loc, POP_TOP);
4023+
ADDOP_I(c, loc, SWAP, 2);
4024+
ADDOP(c, loc, POP_TOP);
40224025
}
40234026
if (!compiler_nameop(c, loc, asname, Store)) {
4024-
return 0;
4027+
return ERROR;
40254028
}
4026-
_ADDOP(c, loc, POP_TOP);
4027-
return 1;
4029+
ADDOP(c, loc, POP_TOP);
4030+
return SUCCESS;
40284031
}
4029-
return compiler_nameop(c, loc, asname, Store);
4032+
return compiler_nameop(c, loc, asname, Store) ? SUCCESS : ERROR;
40304033
}
40314034

40324035
static int
@@ -4047,33 +4050,36 @@ compiler_import(struct compiler *c, stmt_ty s)
40474050
alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);
40484051
int r;
40494052

4050-
_ADDOP_LOAD_CONST(c, loc, zero);
4051-
_ADDOP_LOAD_CONST(c, loc, Py_None);
4052-
_ADDOP_NAME(c, loc, IMPORT_NAME, alias->name, names);
4053+
ADDOP_LOAD_CONST(c, loc, zero);
4054+
ADDOP_LOAD_CONST(c, loc, Py_None);
4055+
ADDOP_NAME(c, loc, IMPORT_NAME, alias->name, names);
40534056

40544057
if (alias->asname) {
40554058
r = compiler_import_as(c, loc, alias->name, alias->asname);
4056-
if (!r)
4059+
if (r == ERROR) {
40574060
return r;
4061+
}
40584062
}
40594063
else {
40604064
identifier tmp = alias->name;
40614065
Py_ssize_t dot = PyUnicode_FindChar(
40624066
alias->name, '.', 0, PyUnicode_GET_LENGTH(alias->name), 1);
40634067
if (dot != -1) {
40644068
tmp = PyUnicode_Substring(alias->name, 0, dot);
4065-
if (tmp == NULL)
4066-
return 0;
4069+
if (tmp == NULL) {
4070+
return ERROR;
4071+
}
40674072
}
40684073
r = compiler_nameop(c, loc, tmp, Store);
40694074
if (dot != -1) {
40704075
Py_DECREF(tmp);
40714076
}
4072-
if (!r)
4073-
return r;
4077+
if (!r) {
4078+
return ERROR;
4079+
}
40744080
}
40754081
}
4076-
return 1;
4082+
return SUCCESS;
40774083
}
40784084

40794085
static int
@@ -4250,7 +4256,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
42504256
case Assert_kind:
42514257
return compiler_assert(c, s) == SUCCESS ? 1 : 0;
42524258
case Import_kind:
4253-
return compiler_import(c, s);
4259+
return compiler_import(c, s) == SUCCESS ? 1 : 0;
42544260
case ImportFrom_kind:
42554261
return compiler_from_import(c, s);
42564262
case Global_kind:

0 commit comments

Comments
 (0)
0