Fix #566, where __getslice__ generates code that gives a confusing compiler error...
authorCarl Witty <Carl.Witty@gmail.com>
Thu, 12 Aug 2010 16:36:40 +0000 (09:36 -0700)
committerCarl Witty <Carl.Witty@gmail.com>
Thu, 12 Aug 2010 16:36:40 +0000 (09:36 -0700)
Cython/Compiler/ModuleNode.py

index 8b15bafcc9c41b11f2e0dbb0d0e7b85b3dcf9645..c88fb7b242c647481fa6654b5a6a3ec74bf49296 100644 (file)
@@ -932,8 +932,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
                         self.generate_getitem_int_function(scope, code)
                     if scope.defines_any(["__setitem__", "__delitem__"]):
                         self.generate_ass_subscript_function(scope, code)
+                    if scope.defines_any(["__getslice__", "__setslice__", "__delslice__"]):
+                        warning(self.pos, "__getslice__, __setslice__, and __delslice__ are not supported by Python 3, use __getitem__, __setitem__, and __delitem__ instead", 1)
+                        code.putln("#if PY_MAJOR_VERSION >= 3")
+                        code.putln("#error __getslice__, __setslice__, and __delslice__ not supported in Python 3.")
+                        code.putln("#endif")
                     if scope.defines_any(["__setslice__", "__delslice__"]):
-                        warning(self.pos, "__setslice__ and __delslice__ are not supported by Python 3, use __setitem__ and __getitem__ instead", 1)
                         self.generate_ass_slice_function(scope, code)
                     if scope.defines_any(["__getattr__","__getattribute__"]):
                         self.generate_getattro_function(scope, code)
@@ -1260,9 +1264,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         # Setting and deleting a slice are both done through
         # the ass_slice method, so we dispatch to user's __setslice__
         # or __delslice__, or raise an exception.
-        code.putln("#if PY_MAJOR_VERSION >= 3")
-        code.putln("#error __setslice__ and __delslice__ not supported in Python 3.")
-        code.putln("#endif")
         base_type = scope.parent_type.base_type
         set_entry = scope.lookup_here("__setslice__")
         del_entry = scope.lookup_here("__delslice__")