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
Kirill Smelkov
cython
Commits
ac48e447
Commit
ac48e447
authored
Nov 07, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reject properties with additional decorators in cdef classes
parent
a27d2259
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
23 deletions
+75
-23
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+33
-23
tests/errors/cdef_class_properties_decorated.pyx
tests/errors/cdef_class_properties_decorated.pyx
+42
-0
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
ac48e447
...
...
@@ -1299,30 +1299,40 @@ class PropertyTransform(ScopeTrackingTransform):
if
self
.
scope_type
!=
'cclass'
or
not
node
.
decorators
:
return
node
properties
=
self
.
_properties
[
-
1
]
# restrict transformation to outermost decorator as wrapped properties will probably not work
decorator_node
=
node
.
decorators
[
-
1
]
decorator
=
decorator_node
.
decorator
if
decorator
.
is_name
and
decorator
.
name
==
'property'
:
name
=
node
.
name
node
.
name
=
'__get__'
node
.
decorators
.
remove
(
decorator_node
)
stat_list
=
[
node
]
if
name
in
properties
:
prop
=
properties
[
name
]
prop
.
pos
=
node
.
pos
for
decorator_node
in
node
.
decorators
[::
-
1
]:
decorator
=
decorator_node
.
decorator
if
decorator
.
is_name
and
decorator
.
name
==
'property'
:
if
len
(
node
.
decorators
)
>
1
:
return
self
.
_reject_decorated_property
(
node
,
decorator_node
)
name
=
node
.
name
node
.
name
=
'__get__'
node
.
decorators
.
remove
(
decorator_node
)
stat_list
=
[
node
]
if
name
in
properties
:
prop
=
properties
[
name
]
prop
.
pos
=
node
.
pos
prop
.
doc
=
node
.
doc
prop
.
body
.
stats
=
stat_list
return
[]
prop
=
Nodes
.
PropertyNode
(
node
.
pos
,
name
=
name
)
prop
.
doc
=
node
.
doc
prop
.
body
.
stats
=
stat_list
return
[]
prop
=
Nodes
.
PropertyNode
(
node
.
pos
,
name
=
name
)
prop
.
doc
=
node
.
doc
prop
.
body
=
Nodes
.
StatListNode
(
node
.
pos
,
stats
=
stat_list
)
properties
[
name
]
=
prop
return
[
prop
]
elif
decorator
.
is_attribute
and
decorator
.
obj
.
name
in
properties
:
handler_name
=
self
.
_map_property_attribute
(
decorator
.
attribute
)
if
handler_name
:
assert
decorator
.
obj
.
name
==
node
.
name
return
self
.
_add_to_property
(
properties
,
node
,
handler_name
,
decorator_node
)
prop
.
body
=
Nodes
.
StatListNode
(
node
.
pos
,
stats
=
stat_list
)
properties
[
name
]
=
prop
return
[
prop
]
elif
decorator
.
is_attribute
and
decorator
.
obj
.
name
in
properties
:
handler_name
=
self
.
_map_property_attribute
(
decorator
.
attribute
)
if
handler_name
:
assert
decorator
.
obj
.
name
==
node
.
name
if
len
(
node
.
decorators
)
>
1
:
return
self
.
_reject_decorated_property
(
node
,
decorator_node
)
return
self
.
_add_to_property
(
properties
,
node
,
handler_name
,
decorator_node
)
return
node
def
_reject_decorated_property
(
self
,
node
,
decorator_node
):
# restrict transformation to outermost decorator as wrapped properties will probably not work
for
deco
in
node
.
decorators
:
if
deco
!=
decorator_node
:
error
(
deco
.
pos
,
"Property methods with additional decorators are not supported"
)
return
node
def
_add_to_property
(
self
,
properties
,
node
,
name
,
decorator
):
...
...
tests/errors/cdef_class_properties_decorated.pyx
0 → 100644
View file @
ac48e447
# mode: error
# ticket: 264
# tag: property, decorator
from
functools
import
wraps
def
wrap_func
(
f
):
@
wraps
(
f
)
def
wrap
(
*
args
,
**
kwargs
):
print
(
"WRAPPED"
)
return
f
(
*
args
,
**
kwargs
)
return
wrap
cdef
class
Prop
:
@
property
@
wrap_func
def
prop1
(
self
):
return
1
@
property
def
prop2
(
self
):
return
2
@
wrap_func
@
prop2
.
setter
def
prop2
(
self
,
value
):
pass
@
prop2
.
setter
@
wrap_func
def
prop2
(
self
,
value
):
pass
_ERRORS
=
"""
19:4: Property methods with additional decorators are not supported
27:4: Property methods with additional decorators are not supported
33:4: Property methods with additional decorators are not supported
"""
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