summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-10-03 20:29:54 +0200
committerStefan Behnel <stefan_ml@behnel.de>2017-10-03 20:29:54 +0200
commit1d37f2ae8c0754a9c823f5ca88641778858f9204 (patch)
treebe49c9c769751be371e11a0b11cdbcbaa6d5a8b0
parent69c04ee7efd868b32726ca694d41439ba674a468 (diff)
downloadcython-1d37f2ae8c0754a9c823f5ca88641778858f9204.tar.gz
Turn compiler assertion into an error since it's triggered by user code.
Considered to make it a warning, but CPython's forgiving behaviour seems unhelpful. Can still make it a warning later. Closed #1905.
-rw-r--r--Cython/Compiler/ParseTreeTransforms.py11
-rw-r--r--tests/errors/cdef_class_properties_decorated.pyx5
2 files changed, 13 insertions, 3 deletions
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py
index 7ee9861a8..f74ac3beb 100644
--- a/Cython/Compiler/ParseTreeTransforms.py
+++ b/Cython/Compiler/ParseTreeTransforms.py
@@ -1385,10 +1385,15 @@ class DecoratorTransform(ScopeTrackingTransform, SkipDeclarations):
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:
+ if decorator.obj.name != node.name:
+ # CPython does not generate an error or warning, but not something useful either.
+ error(decorator_node.pos,
+ "Mismatching property names, expected '%s', got '%s'" % (
+ decorator.obj.name, node.name))
+ elif len(node.decorators) > 1:
return self._reject_decorated_property(node, decorator_node)
- return self._add_to_property(properties, node, handler_name, decorator_node)
+ else:
+ return self._add_to_property(properties, node, handler_name, decorator_node)
# we clear node.decorators, so we need to set the
# is_staticmethod/is_classmethod attributes now
diff --git a/tests/errors/cdef_class_properties_decorated.pyx b/tests/errors/cdef_class_properties_decorated.pyx
index 1bd13d904..7485d8891 100644
--- a/tests/errors/cdef_class_properties_decorated.pyx
+++ b/tests/errors/cdef_class_properties_decorated.pyx
@@ -34,9 +34,14 @@ cdef class Prop:
def prop2(self, value):
pass
+ @prop2.setter
+ def other_name(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
+37:4: Mismatching property names, expected 'prop2', got 'other_name'
"""