Commit d136c751 authored by mattip's avatar mattip

MAINT: refactor decorator analysis

parent f58cc9a8
......@@ -2243,23 +2243,24 @@ class ReplacePropertyNode(CythonTransform):
def visit_CFuncDefNode(self, node):
if not node.decorators:
return node
# transform @property decorators on ctypedef class functions
decorator = self.find_first_decorator(node, 'property')
if decorator:
# transform class functions into c-getters
if len(node.decorators) > 1:
# raises
self._reject_decorated_property(node, decorator_node)
node.entry.is_cgetter = True
# Add a func_cname to be output instead of the attribute
node.entry.func_cname = node.body.stats[0].value.function.name
node.decorators.remove(decorator)
return node
def find_first_decorator(self, node, name):
for decorator_node in node.decorators[::-1]:
if self.find_decorator(decorator_node.decorator, 'property'):
if len(node.decorators) > 1:
# raises
self._reject_decorated_property(node, decorator_node)
node.entry.is_cgetter = True
# Add a func_cname to be output instead of the attribute
node.entry.func_cname = node.body.stats[0].value.function.name
node.decorators.remove(decorator_node)
break
return node
def find_decorator(self, decorator, name):
if decorator.is_name and decorator.name == name:
return True
return False
decorator = decorator_node.decorator
if decorator.is_name and decorator.name == name:
return decorator_node
return None
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