After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 663533 - Calling methods of base class raises "Mutating global variable" error
Calling methods of base class raises "Mutating global variable" error
Status: RESOLVED FIXED
Product: reinteract
Classification: Other
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: reinteract-maint
reinteract-maint
Depends on:
Blocks:
 
 
Reported: 2011-11-07 01:11 UTC by Robert Schroll
Modified: 2012-03-10 15:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Rewrite: switch mutations to objects (6.77 KB, patch)
2012-03-10 15:51 UTC, Owen Taylor
committed Details | Review
rewrite.py: handle mutations in functions at execute time (5.82 KB, patch)
2012-03-10 15:51 UTC, Owen Taylor
committed Details | Review

Description Robert Schroll 2011-11-07 01:11:31 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
Comment 1 Robert Schroll 2011-11-07 02:09:39 UTC
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.
Comment 2 Robert Schroll 2011-12-17 22:17:45 UTC
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).
Comment 3 Owen Taylor 2012-03-10 15:51:26 UTC
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.
Comment 4 Owen Taylor 2012-03-10 15:51:30 UTC
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).
Comment 5 Owen Taylor 2012-03-10 15:51:58 UTC
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