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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
06a30603
Commit
06a30603
authored
Aug 05, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decorators: Added capability to refer to attributes as well (like in Python).
parent
0817b5c8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+7
-3
tests/errors/e_decorators.pyx
tests/errors/e_decorators.pyx
+12
-0
tests/run/decorators.pyx
tests/run/decorators.pyx
+14
-0
No files found.
Cython/Compiler/Parsing.py
View file @
06a30603
...
@@ -2125,9 +2125,13 @@ def p_decorators(s):
...
@@ -2125,9 +2125,13 @@ def p_decorators(s):
while
s
.
sy
==
'DECORATOR'
:
while
s
.
sy
==
'DECORATOR'
:
pos
=
s
.
position
()
pos
=
s
.
position
()
s
.
next
()
s
.
next
()
decorator
=
ExprNodes
.
NameNode
(
decstring
=
p_dotted_name
(
s
,
as_allowed
=
0
)[
2
]
pos
,
name
=
Utils
.
EncodedString
(
names
=
decstring
.
split
(
'.'
)
p_dotted_name
(
s
,
as_allowed
=
0
)[
2
]
))
decorator
=
ExprNodes
.
NameNode
(
pos
,
name
=
Utils
.
EncodedString
(
names
[
0
]))
for
name
in
names
[
1
:]:
decorator
=
ExprNodes
.
AttributeNode
(
pos
,
attribute
=
Utils
.
EncodedString
(
name
),
obj
=
decorator
)
if
s
.
sy
==
'('
:
if
s
.
sy
==
'('
:
decorator
=
p_call
(
s
,
decorator
)
decorator
=
p_call
(
s
,
decorator
)
decorators
.
append
(
Nodes
.
DecoratorNode
(
pos
,
decorator
=
decorator
))
decorators
.
append
(
Nodes
.
DecoratorNode
(
pos
,
decorator
=
decorator
))
...
...
tests/errors/e_decorators.pyx
0 → 100644
View file @
06a30603
_ERRORS
=
u"""
4:4 Expected a newline after decorator
"""
class
A
:
pass
@
A
().
a
def
f
():
pass
tests/run/decorators.pyx
View file @
06a30603
...
@@ -13,6 +13,10 @@ __doc__ = u"""
...
@@ -13,6 +13,10 @@ __doc__ = u"""
6
6
>>> h.HERE
>>> h.HERE
1
1
>>> i(4)
3
>>> i.HERE
1
"""
"""
class
wrap
:
class
wrap
:
...
@@ -47,3 +51,13 @@ def g(a,b):
...
@@ -47,3 +51,13 @@ def g(a,b):
@
decorate2
(
1
,
2
)
@
decorate2
(
1
,
2
)
def
h
(
a
,
b
):
def
h
(
a
,
b
):
return
a
+
b
+
3
return
a
+
b
+
3
class
A
:
def
decorate
(
self
,
func
):
return
decorate
(
func
)
a
=
A
()
@
a
.
decorate
def
i
(
x
):
return
x
-
1
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