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
51d8bfc8
Commit
51d8bfc8
authored
Feb 07, 2009
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a simple substitute for functools.wraps to use in importlib._bootstrap.
parent
534b2cd1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
Lib/importlib/NOTES
Lib/importlib/NOTES
+0
-2
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+10
-3
No files found.
Lib/importlib/NOTES
View file @
51d8bfc8
to do
/////
* Backport a poor-man's functools.wraps.
* Implement PEP 302 protocol for loaders (should just be a matter of testing).
+ Built-in.
...
...
Lib/importlib/_bootstrap.py
View file @
51d8bfc8
...
...
@@ -90,6 +90,13 @@ class closing:
self
.
obj
.
close
()
def
wrap
(
new
,
old
):
"""Simple substitute for functools.wraps."""
for
replace
in
[
'__module__'
,
'__name__'
,
'__doc__'
]:
setattr
(
new
,
replace
,
getattr
(
old
,
replace
))
new
.
__dict__
.
update
(
old
.
__dict__
)
def
set___package__
(
fxn
):
"""Set __package__ on the returned module."""
def
wrapper
(
*
args
,
**
kwargs
):
...
...
@@ -99,6 +106,7 @@ def set___package__(fxn):
if
not
hasattr
(
module
,
'__path__'
):
module
.
__package__
=
module
.
__package__
.
rpartition
(
'.'
)[
0
]
return
module
wrap
(
wrapper
,
fxn
)
return
wrapper
...
...
@@ -213,9 +221,7 @@ def check_name(method):
if
self
.
_name
!=
name
:
raise
ImportError
(
"loader cannot handle %s"
%
name
)
return
method
(
self
,
name
,
*
args
,
**
kwargs
)
inner
.
__name__
=
method
.
__name__
inner
.
__doc__
=
method
.
__doc__
inner
.
__dict__
.
update
(
method
.
__dict__
)
wrap
(
inner
,
method
)
return
inner
...
...
@@ -318,6 +324,7 @@ def get_module(fxn):
elif
hasattr
(
module
,
attr
):
delattr
(
module
,
attr
)
raise
wrap
(
decorated
,
fxn
)
return
decorated
...
...
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