Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
49bb2c8e
Commit
49bb2c8e
authored
Dec 04, 2010
by
Tiago Peixoto
Browse files
Fix @_wrap decorator
parent
2c35af58
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/decorators.py
View file @
49bb2c8e
...
...
@@ -40,11 +40,26 @@ def _wraps(func):
thus a bit of a hack, but there no better way I know of to do this."""
def
decorate
(
f
):
argspec
=
inspect
.
getargspec
(
func
)
args_call
=
inspect
.
formatargspec
(
argspec
[
0
])
argspec
=
inspect
.
formatargspec
(
argspec
[
0
],
defaults
=
argspec
[
3
])
___wrap_defaults
=
defaults
=
argspec
[
-
1
]
if
defaults
is
not
None
:
def_string
=
[
"___wrap_defaults[%d]"
%
d
for
d
in
xrange
(
len
(
defaults
))]
def_names
=
argspec
[
0
][
-
len
(
defaults
):]
else
:
def_string
=
None
def_names
=
None
args_call
=
inspect
.
formatargspec
(
argspec
[
0
],
defaults
=
def_names
)
argspec
=
inspect
.
formatargspec
(
argspec
[
0
],
defaults
=
def_string
)
argspec
=
argspec
.
lstrip
(
"("
).
rstrip
(
")"
)
wrap
=
eval
(
"lambda %s: f%s"
%
(
argspec
,
args_call
),
locals
())
return
functools
.
wraps
(
func
)(
wrap
)
wf
=
"def %s(%s):
\n
return f%s
\n
"
%
\
(
func
.
__name__
,
argspec
,
args_call
)
if
def_string
is
not
None
:
for
d
in
def_string
:
wf
=
wf
.
replace
(
"'%s'"
%
d
,
"%s"
%
d
)
for
d
in
def_names
:
wf
=
wf
.
replace
(
"'%s'"
%
d
,
"%s"
%
d
)
exec
wf
in
locals
()
return
functools
.
wraps
(
func
)(
locals
()[
func
.
__name__
])
return
decorate
...
...
Write
Preview
Supports
Markdown
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