Fix self-assignment warnings.
authorRobert Bradshaw <robertwb@gmail.com>
Fri, 4 Oct 2013 06:21:45 +0000 (23:21 -0700)
committerRobert Bradshaw <robertwb@gmail.com>
Fri, 4 Oct 2013 06:21:45 +0000 (23:21 -0700)
This is somewhat of a Gordian Knot approach, but seems to do the trick.

Cython/Compiler/Code.py

index 1f51f1f..c2f4af9 100644 (file)
@@ -62,6 +62,8 @@ modifier_output_mapper = {
     'inline': 'CYTHON_INLINE'
 }.get
 
+is_self_assignment = re.compile(r" *(\w+) = (\1);\s*$").match
+
 
 def get_utility_dir():
     # make this a function and not global variables:
@@ -1555,6 +1557,8 @@ class CCodeWriter(object):
         self.put(code)
 
     def put(self, code):
+        if is_self_assignment(code):
+            return
         fix_indent = False
         if "{" in code:
             dl = code.count("{")