sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Error while appending to a list "ExecutionError: obj.push is not a function" (firefox 17.0.1) #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In console:

def instance_repr(o):
    if isinstance(o, list):
        l = []
        for i in o:
            l.append( instance_repr(i) )
        s = "[ %s ]" % ", ".join(l)
    elif isinstance(o, str):
        # TODO other control characters
        s = str(o)
        s = s.replace("'", "\\'")
    elif isinstance(o, int):
        s = str(o)
    else:
        s = o.__class__
    return s

n = [ 1, 2, 3, 4 ]
print( instance_repr(n) )

n = [ "A", "B", "C", "D" ]
print( instance_repr(n) )

Result in:
[ 1, 2, 3, 4 ]
and the given error

For some strange reason, while dealing with the second test case,
it seems that the code ends up trying do perform an "append" on "A" string.

Notice that using an intermediate variable addresses the issue:
            l.append( instance_repr(i) )
replaced by
            x = instance_repr(i)
            l.append(x)

Original issue reported on code.google.com by pedro.ro...@gmail.com on 30 Dec 2012 at 10:40

GoogleCodeExporter commented 9 years ago
Fixed in revision 282 : missing "var" before variable obj in method 
list.append()

Original comment by pierre.q...@gmail.com on 31 Dec 2012 at 8:36