GNOME Bugzilla – Bug 663533
Calling methods of base class raises "Mutating global variable" error
Last modified: 2012-03-10 15:52:04 UTC
Reinteract mistakes the call of a base class method BaseClass.method(self) as a mutation of BaseClass. Using super doesn't help--this is mistaken as a mutation of super. Reported on the mailing list: http://groups.google.com/group/reinteract/browse_thread/thread/ec205fd776afc539
I fear that this is going to be hard to do correctly just at the syntax level, since it looks identical to 'object.method(args)'. Maybe, though, we can prevent most problems with a heuristic solution: If the first argument of a method call is 'self', assume that it's a base class method call and don't object about mutations.
A similar problem arises when calling a function from a module. For example: import time def wait(): time.sleep(1) To make this work, I think we'd have to wait until execution time to see if 'time' is a module, a class, or a global object. But I'm left wondering if this is worth it. Perhaps it's better to just disable this check for now. Another approach would be to add some kind of notation to the resultant function object that 'time' in the global scope will be modified on execution. This could be added to the mutation collector. This would allow mutations of globals in functions to actually work, and the issues here would turn into warnings about not being able to copy (which could then be suppressed).
Created attachment 209395 [details] [review] Rewrite: switch mutations to objects Rather than returning a list of tuples for mutations, return an object that encapsulates the process of copying in the scope.
Created attachment 209396 [details] [review] rewrite.py: handle mutations in functions at execute time Rather than throwing an error immediately when we see a mutation in a function, wait until the function definition is executed - that gives us a better chance of distinguishing time.sleep(1) from global_array.append(1).
Attachment 209395 [details] pushed as 7e04a1c - Rewrite: switch mutations to objects Attachment 209396 [details] pushed as 99e1721 - rewrite.py: handle mutations in functions at execute time