Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
84c37f4e
Commit
84c37f4e
authored
Jun 25, 2017
by
scoder
Committed by
GitHub
Jun 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1724 from jdemeyer/cyfunction_decorators
Do not apply decorators twice
parents
3ae067f3
99e40cd2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
2 deletions
+58
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+11
-1
tests/run/cyfunction.pyx
tests/run/cyfunction.pyx
+44
-0
No files found.
Cython/Compiler/Nodes.py
View file @
84c37f4e
...
@@ -2646,6 +2646,9 @@ class DefNode(FuncDefNode):
...
@@ -2646,6 +2646,9 @@ class DefNode(FuncDefNode):
child_attrs
=
[
"args"
,
"star_arg"
,
"starstar_arg"
,
"body"
,
"decorators"
,
"return_type_annotation"
]
child_attrs
=
[
"args"
,
"star_arg"
,
"starstar_arg"
,
"body"
,
"decorators"
,
"return_type_annotation"
]
is_staticmethod
=
False
is_classmethod
=
False
lambda_name
=
None
lambda_name
=
None
reqd_kw_flags_cname
=
"0"
reqd_kw_flags_cname
=
"0"
is_wrapper
=
0
is_wrapper
=
0
...
@@ -2758,7 +2761,6 @@ class DefNode(FuncDefNode):
...
@@ -2758,7 +2761,6 @@ class DefNode(FuncDefNode):
return
True
return
True
def
analyse_declarations
(
self
,
env
):
def
analyse_declarations
(
self
,
env
):
self
.
is_classmethod
=
self
.
is_staticmethod
=
False
if
self
.
decorators
:
if
self
.
decorators
:
for
decorator
in
self
.
decorators
:
for
decorator
in
self
.
decorators
:
func
=
decorator
.
decorator
func
=
decorator
.
decorator
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
84c37f4e
...
@@ -1337,8 +1337,18 @@ class DecoratorTransform(ScopeTrackingTransform, SkipDeclarations):
...
@@ -1337,8 +1337,18 @@ class DecoratorTransform(ScopeTrackingTransform, SkipDeclarations):
return
self
.
_reject_decorated_property
(
node
,
decorator_node
)
return
self
.
_reject_decorated_property
(
node
,
decorator_node
)
return
self
.
_add_to_property
(
properties
,
node
,
handler_name
,
decorator_node
)
return
self
.
_add_to_property
(
properties
,
node
,
handler_name
,
decorator_node
)
# we clear node.decorators, so we need to set the
# is_staticmethod/is_classmethod attributes now
for
decorator
in
node
.
decorators
:
func
=
decorator
.
decorator
if
func
.
is_name
:
node
.
is_classmethod
|=
func
.
name
==
'classmethod'
node
.
is_staticmethod
|=
func
.
name
==
'staticmethod'
# transform normal decorators
# transform normal decorators
return
self
.
chain_decorators
(
node
,
node
.
decorators
,
node
.
name
)
decs
=
node
.
decorators
node
.
decorators
=
None
return
self
.
chain_decorators
(
node
,
decs
,
node
.
name
)
@
staticmethod
@
staticmethod
def
_reject_decorated_property
(
node
,
decorator_node
):
def
_reject_decorated_property
(
node
,
decorator_node
):
...
...
tests/run/cyfunction.pyx
View file @
84c37f4e
...
@@ -304,3 +304,47 @@ def test_annotations(a: "test", b: "other" = 2, c: 123 = 4) -> "ret":
...
@@ -304,3 +304,47 @@ def test_annotations(a: "test", b: "other" = 2, c: 123 = 4) -> "ret":
def
inner
(
x
:
"banana"
,
y
:
b
())
->
c
():
def
inner
(
x
:
"banana"
,
y
:
b
())
->
c
():
return
x
,
y
return
x
,
y
return
inner
return
inner
def
add_one
(
func
):
"Decorator to add 1 to the last argument of the function call"
def
inner
(
*
args
):
args
=
args
[:
-
1
]
+
(
args
[
-
1
]
+
1
,)
return
func
(
*
args
)
return
inner
@
add_one
def
test_decorated
(
x
):
"""
>>> test_decorated(0)
1
"""
return
x
@
add_one
@
add_one
def
test_decorated2
(
x
):
"""
>>> test_decorated2(0)
2
"""
return
x
cdef
class
TestDecoratedMethods
:
@
add_one
def
test
(
self
,
x
):
"""
>>> TestDecoratedMethods().test(0)
1
"""
return
x
@
add_one
@
add_one
def
test2
(
self
,
x
):
"""
>>> TestDecoratedMethods().test2(0)
2
"""
return
x
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