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
5c0a6de7
Commit
5c0a6de7
authored
Feb 25, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Glyph's trick to ensure that __globals__ is set properly.
parent
55b4a4a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
Lib/xreload.py
Lib/xreload.py
+14
-14
No files found.
Lib/xreload.py
View file @
5c0a6de7
...
...
@@ -55,22 +55,22 @@ def xreload(mod):
finally
:
if
stream
:
stream
.
close
()
# Execute the code in a temporary namespace; if this fails, no changes
tmpns
=
{}
exec
(
code
,
tmpns
)
# Execute the code. We copy the module dict to a temporary; then
# clear the module dict; then execute the new code in the module
# dict; then swap things back and around. This trick (due to
# Glyph Lefkowitz) ensures that the (readonly) __globals__
# attribute of methods and functions is set to the correct dict
# object.
tmpns
=
modns
.
copy
()
modns
.
clear
()
modns
[
"__name__"
]
=
tmpns
[
"__name__"
]
exec
(
code
,
modns
)
# Now we get to the hard part
oldnames
=
set
(
modns
)
newnames
=
set
(
tmpns
)
# Add newly introduced names
for
name
in
newnames
-
oldnames
:
modns
[
name
]
=
tmpns
[
name
]
# Delete names that are no longer current
# XXX What to do about renamed objects?
for
name
in
oldnames
-
newnames
-
{
"__name__"
}:
del
modns
[
name
]
# Now update the rest in place
oldnames
=
set
(
tmpns
)
newnames
=
set
(
modns
)
# Update attributes in place
for
name
in
oldnames
&
newnames
:
modns
[
name
]
=
_update
(
modns
[
name
],
tmp
ns
[
name
])
modns
[
name
]
=
_update
(
tmpns
[
name
],
mod
ns
[
name
])
# Done!
return
mod
...
...
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