cpython: eb68502731dd (original) (raw)

Mercurial > cpython

changeset 76640:eb68502731dd

Issues #13959, 14647: Re-implement imp.reload() in Lib/imp.py. Thanks to Eric Snow for the patch. [#13959]

Brett Cannon brett@python.org
date Sun, 29 Apr 2012 14:38:11 -0400
parents 1255cac63dfc
children 40a05f9eb4c6
files Include/pystate.h Lib/imp.py Objects/moduleobject.c Python/import.c Python/pystate.c Python/pythonrun.c
diffstat 6 files changed, 47 insertions(+), 108 deletions(-)[+] [-] Include/pystate.h 1 Lib/imp.py 33 Objects/moduleobject.c 2 Python/import.c 113 Python/pystate.c 2 Python/pythonrun.c 4

line wrap: on

line diff

--- a/Include/pystate.h +++ b/Include/pystate.h @@ -26,7 +26,6 @@ typedef struct _is { PyObject *sysdict; PyObject *builtins; PyObject *importlib;

PyObject *codec_search_path; PyObject *codec_search_cache;

--- a/Lib/imp.py +++ b/Lib/imp.py @@ -6,7 +6,7 @@ functionality over this module. """

(Probably) need to stay in _imp

-from _imp import (lock_held, acquire_lock, release_lock, reload, +from _imp import (lock_held, acquire_lock, release_lock, load_dynamic, get_frozen_object, is_frozen_package, init_builtin, init_frozen, is_builtin, is_frozen, fix_co_filename) @@ -207,3 +207,34 @@ def find_module(name, path=None): encoding = tokenize.detect_encoding(file.readline)[0] file = open(file_path, mode, encoding=encoding) return file, file_path, (suffix, mode, type) + + +_RELOADING = {} + +def reload(module):

+

+

+

--- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -285,7 +285,7 @@ void pos = 0; while (PyDict_Next(d, &pos, &key, &value)) { if (value != Py_None && PyUnicode_Check(key)) {

--- a/Python/import.c +++ b/Python/import.c @@ -410,14 +410,6 @@ void #endif } -static void -imp_modules_reloading_clear(void) -{

-} - /* Helper for sys */ PyObject * @@ -575,7 +567,6 @@ PyImport_Cleanup(void) PyDict_Clear(modules); interp->modules = NULL; Py_DECREF(modules);

} @@ -1783,87 +1774,23 @@ PyImport_ImportModuleLevel(const char *n PyObject * PyImport_ReloadModule(PyObject *m) {

-

-

-

- -error:

} @@ -2160,17 +2087,6 @@ imp_load_dynamic(PyObject self, PyObjec #endif / HAVE_DYNAMIC_LOADING */ -static PyObject * -imp_reload(PyObject *self, PyObject *v) -{

-} - -PyDoc_STRVAR(doc_reload, -"reload(module) -> module\n[](#l4.139) -\n[](#l4.140) -Reload the module. The module must have been successfully imported before."); - /* Doc strings */ @@ -2214,7 +2130,6 @@ static PyMethodDef imp_methods[] = { {"lock_held", imp_lock_held, METH_NOARGS, doc_lock_held}, {"acquire_lock", imp_acquire_lock, METH_NOARGS, doc_acquire_lock}, {"release_lock", imp_release_lock, METH_NOARGS, doc_release_lock},

--- a/Python/pystate.c +++ b/Python/pystate.c @@ -69,7 +69,6 @@ PyInterpreterState_New(void) Py_FatalError("Can't initialize threads for interpreter"); #endif interp->modules = NULL;

@@ -114,7 +113,6 @@ PyInterpreterState_Clear(PyInterpreterSt Py_CLEAR(interp->codec_error_registry); Py_CLEAR(interp->modules); Py_CLEAR(interp->modules_by_index);

--- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -314,9 +314,6 @@ Py_InitializeEx(int install_sigs) interp->modules = PyDict_New(); if (interp->modules == NULL) Py_FatalError("Py_Initialize: can't make modules dictionary");

/* Init Unicode implementation; relies on the codec registry */ if (_PyUnicode_Init() < 0) @@ -680,7 +677,6 @@ Py_NewInterpreter(void) /* XXX The following is lax in error checking */ interp->modules = PyDict_New();

bimod = _PyImport_FindBuiltin("builtins"); if (bimod != NULL) {