Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
5aabdb34
Commit
5aabdb34
authored
Jan 22, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imp.load_module has to always set __file__ even if the module already exists
parent
eb3b2738
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
src/runtime/types.cpp
src/runtime/types.cpp
+9
-6
test/tests/imp_test.py
test/tests/imp_test.py
+8
-0
No files found.
src/runtime/types.cpp
View file @
5aabdb34
...
...
@@ -4171,21 +4171,24 @@ BoxedModule* createModule(BoxedString* name, const char* fn, const char* doc) {
BoxedDict
*
d
=
getSysModulesDict
();
BoxedModule
*
module
=
NULL
;
// Surprisingly, there are times that we need to return the existing module if
// one exists:
Box
*
existing
=
d
->
getOrNull
(
name
);
if
(
existing
&&
PyModule_Check
(
existing
))
{
return
static_cast
<
BoxedModule
*>
(
existing
);
module
=
static_cast
<
BoxedModule
*>
(
existing
);
}
else
{
module
=
new
BoxedModule
();
moduleInit
(
module
,
name
,
boxString
(
doc
?
doc
:
""
));
d
->
d
[
name
]
=
module
;
}
BoxedModule
*
module
=
new
BoxedModule
();
moduleInit
(
module
,
name
,
boxString
(
doc
?
doc
:
""
));
if
(
fn
)
module
->
giveAttr
(
"__file__"
,
boxString
(
fn
)
);
module
->
setattr
(
internStringMortal
(
"__file__"
),
boxString
(
fn
),
NULL
);
d
->
d
[
name
]
=
module
;
if
(
name
->
s
()
==
"__main__"
)
module
->
giveAttr
(
"__builtins__"
,
builtins_module
);
module
->
setattr
(
internStringMortal
(
"__builtins__"
),
builtins_module
,
NULL
);
return
module
;
}
...
...
test/tests/imp_test.py
View file @
5aabdb34
...
...
@@ -35,3 +35,11 @@ def n(s):
return
str
(
s
).
replace
(
".pyc"
,
".py"
)
print
n
(
m
),
n
(
m
.
__name__
),
n
(
m
.
__file__
),
hasattr
(
m
,
"__path__"
)
import
sys
,
types
name
=
"json"
m
=
sys
.
modules
[
name
]
=
types
.
ModuleType
(
name
)
print
sorted
(
dir
(
m
))
s
=
imp
.
find_module
(
name
)
m
=
imp
.
load_module
(
name
,
*
s
)
print
name
in
m
.
__file__
,
sorted
(
dir
(
m
))
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