Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
13a7a212
Commit
13a7a212
authored
Jan 07, 2008
by
Christian Heimes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1762972: Readded the reload() function as imp.reload()
parent
8de8e038
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
Lib/test/test_imp.py
Lib/test/test_imp.py
+8
-0
Lib/test/test_import.py
Lib/test/test_import.py
+40
-0
Python/import.c
Python/import.c
+12
-0
No files found.
Lib/test/test_imp.py
View file @
13a7a212
...
@@ -60,6 +60,14 @@ class ImportTests(unittest.TestCase):
...
@@ -60,6 +60,14 @@ class ImportTests(unittest.TestCase):
'"""Tokenization help for Python programs.
\
n
'
)
'"""Tokenization help for Python programs.
\
n
'
)
fp
.
close
()
fp
.
close
()
def
test_reload
(
self
):
import
marshal
imp
.
reload
(
marshal
)
import
string
imp
.
reload
(
string
)
## import sys
## self.assertRaises(ImportError, reload, sys)
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
test_support
.
run_unittest
(
...
...
Lib/test/test_import.py
View file @
13a7a212
...
@@ -7,6 +7,7 @@ import shutil
...
@@ -7,6 +7,7 @@ import shutil
import
sys
import
sys
import
py_compile
import
py_compile
import
warnings
import
warnings
import
imp
from
test.test_support
import
unlink
,
TESTFN
,
unload
from
test.test_support
import
unlink
,
TESTFN
,
unload
...
@@ -160,6 +161,45 @@ class ImportTest(unittest.TestCase):
...
@@ -160,6 +161,45 @@ class ImportTest(unittest.TestCase):
warnings
.
simplefilter
(
'error'
,
ImportWarning
)
warnings
.
simplefilter
(
'error'
,
ImportWarning
)
self
.
assertRaises
(
ImportWarning
,
__import__
,
"site-packages"
)
self
.
assertRaises
(
ImportWarning
,
__import__
,
"site-packages"
)
def
test_failing_reload
(
self
):
# A failing reload should leave the module object in sys.modules.
source
=
TESTFN
+
".py"
with
open
(
source
,
"w"
)
as
f
:
f
.
write
(
"a = 1
\
n
b=2
\
n
"
)
sys
.
path
.
insert
(
0
,
os
.
curdir
)
try
:
mod
=
__import__
(
TESTFN
)
self
.
assert_
(
TESTFN
in
sys
.
modules
,
"expected module in sys.modules"
)
self
.
assertEquals
(
mod
.
a
,
1
,
"module has wrong attribute values"
)
self
.
assertEquals
(
mod
.
b
,
2
,
"module has wrong attribute values"
)
# On WinXP, just replacing the .py file wasn't enough to
# convince reload() to reparse it. Maybe the timestamp didn't
# move enough. We force it to get reparsed by removing the
# compiled file too.
remove_files
(
TESTFN
)
# Now damage the module.
with
open
(
source
,
"w"
)
as
f
:
f
.
write
(
"a = 10
\
n
b=20//0
\
n
"
)
self
.
assertRaises
(
ZeroDivisionError
,
imp
.
reload
,
mod
)
# But we still expect the module to be in sys.modules.
mod
=
sys
.
modules
.
get
(
TESTFN
)
self
.
failIf
(
mod
is
None
,
"expected module to still be in sys.modules"
)
# We should have replaced a w/ 10, but the old b value should
# stick.
self
.
assertEquals
(
mod
.
a
,
10
,
"module has wrong attribute values"
)
self
.
assertEquals
(
mod
.
b
,
2
,
"module has wrong attribute values"
)
finally
:
sys
.
path
.
pop
(
0
)
remove_files
(
TESTFN
)
if
TESTFN
in
sys
.
modules
:
del
sys
.
modules
[
TESTFN
]
class
PathsTests
(
unittest
.
TestCase
):
class
PathsTests
(
unittest
.
TestCase
):
SAMPLES
=
(
'test'
,
'test
\
u00e4
\
u00f6
\
u00fc
\
u00df
'
,
'test
\
u00e9
\
u00e8
'
,
SAMPLES
=
(
'test'
,
'test
\
u00e4
\
u00f6
\
u00fc
\
u00df
'
,
'test
\
u00e9
\
u00e8
'
,
'test
\
u00b0
\
u00b3
\
u00b2
'
)
'test
\
u00b0
\
u00b3
\
u00b2
'
)
...
...
Python/import.c
View file @
13a7a212
...
@@ -2931,6 +2931,17 @@ imp_new_module(PyObject *self, PyObject *args)
...
@@ -2931,6 +2931,17 @@ imp_new_module(PyObject *self, PyObject *args)
return
PyModule_New
(
name
);
return
PyModule_New
(
name
);
}
}
static
PyObject
*
imp_reload
(
PyObject
*
self
,
PyObject
*
v
)
{
return
PyImport_ReloadModule
(
v
);
}
PyDoc_STRVAR
(
doc_reload
,
"reload(module) -> module
\n
\
\n
\
Reload the module. The module must have been successfully imported before."
);
/* Doc strings */
/* Doc strings */
PyDoc_STRVAR
(
doc_imp
,
PyDoc_STRVAR
(
doc_imp
,
...
@@ -2989,6 +3000,7 @@ static PyMethodDef imp_methods[] = {
...
@@ -2989,6 +3000,7 @@ static PyMethodDef imp_methods[] = {
{
"lock_held"
,
imp_lock_held
,
METH_NOARGS
,
doc_lock_held
},
{
"lock_held"
,
imp_lock_held
,
METH_NOARGS
,
doc_lock_held
},
{
"acquire_lock"
,
imp_acquire_lock
,
METH_NOARGS
,
doc_acquire_lock
},
{
"acquire_lock"
,
imp_acquire_lock
,
METH_NOARGS
,
doc_acquire_lock
},
{
"release_lock"
,
imp_release_lock
,
METH_NOARGS
,
doc_release_lock
},
{
"release_lock"
,
imp_release_lock
,
METH_NOARGS
,
doc_release_lock
},
{
"reload"
,
imp_reload
,
METH_O
,
doc_reload
},
/* The rest are obsolete */
/* The rest are obsolete */
{
"get_frozen_object"
,
imp_get_frozen_object
,
METH_VARARGS
},
{
"get_frozen_object"
,
imp_get_frozen_object
,
METH_VARARGS
},
{
"init_builtin"
,
imp_init_builtin
,
METH_VARARGS
},
{
"init_builtin"
,
imp_init_builtin
,
METH_VARARGS
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment