Commit d136c751 authored by mattip's avatar mattip

MAINT: refactor decorator analysis

parent f58cc9a8
...@@ -2243,23 +2243,24 @@ class ReplacePropertyNode(CythonTransform): ...@@ -2243,23 +2243,24 @@ class ReplacePropertyNode(CythonTransform):
def visit_CFuncDefNode(self, node): def visit_CFuncDefNode(self, node):
if not node.decorators: if not node.decorators:
return node return node
# transform @property decorators on ctypedef class functions decorator = self.find_first_decorator(node, 'property')
for decorator_node in node.decorators[::-1]: if decorator:
if self.find_decorator(decorator_node.decorator, 'property'): # transform class functions into c-getters
if len(node.decorators) > 1: if len(node.decorators) > 1:
# raises # raises
self._reject_decorated_property(node, decorator_node) self._reject_decorated_property(node, decorator_node)
node.entry.is_cgetter = True node.entry.is_cgetter = True
# Add a func_cname to be output instead of the attribute # Add a func_cname to be output instead of the attribute
node.entry.func_cname = node.body.stats[0].value.function.name node.entry.func_cname = node.body.stats[0].value.function.name
node.decorators.remove(decorator_node) node.decorators.remove(decorator)
break
return node return node
def find_decorator(self, decorator, name): def find_first_decorator(self, node, name):
for decorator_node in node.decorators[::-1]:
decorator = decorator_node.decorator
if decorator.is_name and decorator.name == name: if decorator.is_name and decorator.name == name:
return True return decorator_node
return False return None
class FindInvalidUseOfFusedTypes(CythonTransform): class FindInvalidUseOfFusedTypes(CythonTransform):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment