Skip to content

Commit beb6d6e

Browse files
committed
various improvements to ceval.c
1 parent 4c57c8a commit beb6d6e

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

Python/ceval.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,25 +3471,28 @@ _PyEval_ImportNameWithImport(PyThreadState *tstate, PyObject *import_func, PyObj
34713471
ilevel);
34723472
}
34733473

3474-
PyObject* args[5] = {name, globals, locals, fromlist, level};
3474+
PyObject *args[5] = {name, globals, locals, fromlist, level};
34753475
PyObject *res = PyObject_Vectorcall(import_func, args, 5, NULL);
34763476
return res;
34773477
}
34783478

34793479
static int
3480-
check_lazy_import_comatibility(PyThreadState *tstate, PyObject *globals,
3480+
check_lazy_import_compatibility(PyThreadState *tstate, PyObject *globals,
34813481
PyObject *name, PyObject *level)
34823482
{
3483-
// Check if this module should be imported lazily due to the compatbility mode support via
3484-
// __lazy_modules__.
3483+
// Check if this module should be imported lazily due to
3484+
// the compatibility mode support via __lazy_modules__.
34853485
PyObject *lazy_modules = NULL;
34863486
PyObject *abs_name = NULL;
34873487
int res = -1;
34883488

34893489
if (globals != NULL &&
3490-
PyMapping_GetOptionalItem(globals, &_Py_ID(__lazy_modules__), &lazy_modules) < 0) {
3490+
PyMapping_GetOptionalItem(globals, &_Py_ID(__lazy_modules__), &lazy_modules) < 0)
3491+
{
34913492
return -1;
3492-
} else if (lazy_modules == NULL) {
3493+
}
3494+
if (lazy_modules == NULL) {
3495+
assert(!PyErr_Occurred());
34933496
return 0;
34943497
}
34953498

@@ -3530,7 +3533,7 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
35303533

35313534
if (!lazy) {
35323535
// see if __lazy_imports__ forces this to be lazy
3533-
lazy = check_lazy_import_comatibility(tstate, globals, name, level);
3536+
lazy = check_lazy_import_compatibility(tstate, globals, name, level);
35343537
if (lazy < 0) {
35353538
return NULL;
35363539
}
@@ -3544,7 +3547,9 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
35443547
PyObject *lazy_import_func;
35453548
if (PyMapping_GetOptionalItem(builtins, &_Py_ID(__lazy_import__), &lazy_import_func) < 0) {
35463549
goto error;
3547-
} else if (lazy_import_func == NULL) {
3550+
}
3551+
if (lazy_import_func == NULL) {
3552+
assert(!PyErr_Occurred());
35483553
_PyErr_SetString(tstate, PyExc_ImportError, "__lazy_import__ not found");
35493554
goto error;
35503555
}
@@ -3565,7 +3570,7 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
35653570
goto error;
35663571
}
35673572

3568-
PyObject* args[6] = {name, globals, locals, fromlist, level, builtins};
3573+
PyObject *args[6] = {name, globals, locals, fromlist, level, builtins};
35693574
res = PyObject_Vectorcall(lazy_import_func, args, 6, NULL);
35703575
error:
35713576
Py_XDECREF(lazy_import_func);
@@ -3744,7 +3749,8 @@ PyObject *
37443749
_PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
37453750
{
37463751
assert(PyLazyImport_CheckExact(v));
3747-
assert(name && PyUnicode_Check(name));
3752+
assert(name)
3753+
assert(PyUnicode_Check(name));
37483754
PyObject *ret;
37493755
PyLazyImportObject *d = (PyLazyImportObject *)v;
37503756
PyObject *mod = PyImport_GetModule(d->lz_from);
@@ -3756,7 +3762,8 @@ _PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
37563762
if (PyDict_GetItemRef(mod_dict, name, &ret) < 0) {
37573763
Py_DECREF(mod);
37583764
return NULL;
3759-
} else if (ret != NULL) {
3765+
}
3766+
if (ret != NULL) {
37603767
Py_DECREF(mod);
37613768
return ret;
37623769
}
@@ -3775,8 +3782,11 @@ _PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
37753782
Py_DECREF(from);
37763783
return ret;
37773784
}
3778-
} else {
3779-
Py_ssize_t dot = PyUnicode_FindChar(d->lz_from, '.', 0, PyUnicode_GET_LENGTH(d->lz_from), 1);
3785+
}
3786+
else {
3787+
Py_ssize_t dot = PyUnicode_FindChar(
3788+
d->lz_from, '.', 0, PyUnicode_GET_LENGTH(d->lz_from), 1
3789+
);
37803790
if (dot >= 0) {
37813791
PyObject *from = PyUnicode_Substring(d->lz_from, 0, dot);
37823792
if (from == NULL) {

0 commit comments

Comments
 (0)