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
a27d2259
Commit
a27d2259
authored
Nov 07, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor and simplify PropertyTransform
parent
e14dafd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
34 deletions
+34
-34
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+34
-34
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
a27d2259
...
...
@@ -1278,53 +1278,53 @@ class PropertyTransform(ScopeTrackingTransform):
The functional style isn't supported yet.
"""
_properties
=
None
_map_property_attribute
=
{
'getter'
:
'__get__'
,
'setter'
:
'__set__'
,
'deleter'
:
'__del__'
,
}.
get
def
visit_CClassDefNode
(
self
,
node
):
node
.
_properties
=
{}
if
self
.
_properties
is
None
:
self
.
_properties
=
[]
self
.
_properties
.
append
({})
self
.
visit_scope
(
node
,
'cclass'
)
del
node
.
_properties
self
.
_properties
.
pop
()
return
node
def
visit_DefNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
self
.
scope_type
!=
'cclass'
or
not
node
.
decorators
:
return
node
properties
=
self
.
scope_node
.
_properties
for
decorator_node
in
node
.
decorators
[::
-
1
]:
decorator
=
decorator_node
.
decorator
if
(
isinstance
(
decorator
,
ExprNodes
.
NameNode
)
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
prop
.
doc
=
node
.
doc
prop
.
body
.
stats
=
stat_list
return
[]
prop
=
Nodes
.
PropertyNode
(
node
.
pos
,
name
=
name
)
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
prop
.
doc
=
node
.
doc
prop
.
body
=
Nodes
.
StatListNode
(
node
.
pos
,
stats
=
stat_list
)
properties
[
name
]
=
prop
return
[
prop
]
elif
self
.
_test_property_attribute
(
decorator
,
'getter'
,
properties
):
assert
decorator
.
obj
.
name
==
node
.
name
return
self
.
_add_to_property
(
properties
,
node
,
'__get__'
,
decorator_node
)
elif
self
.
_test_property_attribute
(
decorator
,
'setter'
,
properties
):
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
,
'__set__'
,
decorator_node
)
elif
self
.
_test_property_attribute
(
decorator
,
'deleter'
,
properties
):
assert
decorator
.
obj
.
name
==
node
.
name
return
self
.
_add_to_property
(
properties
,
node
,
'__del__'
,
decorator_node
)
return
self
.
_add_to_property
(
properties
,
node
,
handler_name
,
decorator_node
)
return
node
def
_test_property_attribute
(
self
,
decorator
,
name
,
properties
):
return
(
isinstance
(
decorator
,
ExprNodes
.
AttributeNode
)
and
decorator
.
attribute
==
name
and
decorator
.
obj
.
name
in
properties
)
def
_add_to_property
(
self
,
properties
,
node
,
name
,
decorator
):
prop
=
properties
[
node
.
name
]
node
.
name
=
name
...
...
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