Page 1 of 1

Syntax error in glue code

PostPosted: Wed Jun 25, 2008 3:30 pm
by Branan
I'm getting a syntax error from Python in the glue code. This is in a Cyan-standard file, not in a custom python file. All of Cyan's files have this line, though. It may be a result of the decompyler doing something weird. The line is in thefunction glue_findAndAddAttribs(obj, glue_params)
Code: Select all
elif (type(obj) == type((,))):


I'm 90% sure it's checking if obj is a tuple, in which case changing type((,)) to type(()) (the inner parenthesis make an empty tuple) should work fine. Wanted to get a second opinion first, though.

I'm not sure I should post the full function from the glue code or not - this is one of Cyan's files, after all. The glue code in the Pahts files is slightly different.

EDIT: nevermind, found the exact same function in Pahts glue code. here it is:
Code: Select all
def glue_findAndAddAttribs(obj, glue_params):
    if isinstance(obj, ptAttribute):
        if glue_params.has_key(obj.id):
            if glue_verbose:
                print 'WARNING: Duplicate attribute ids!'
                print ('%s has id %d which is already defined in %s' % (obj.name,
                 obj.id,
                 glue_params[obj.id].name,))
        else:
            glue_params[obj.id] = obj
    elif (type(obj) == type([])):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type({})):
        for o in obj.values():
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type((,))):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)


Looking at it, I think that's ugly. It's testing the types of empty constructs rather than using the build-in TupleType, ListType, etc.

Re: Syntax error in glue code

PostPosted: Wed Jun 25, 2008 3:38 pm
by D'Lanor
I don't have that exact line. The glue code can be found in several posts on this forum so I am not going to worry about posting it here. This is what glue_findAndAddAttribs should look like.

Code: Select all
def glue_findAndAddAttribs(obj, glue_params):
    if isinstance(obj, ptAttribute):
        if glue_params.has_key(obj.id):
            if glue_verbose:
                print 'WARNING: Duplicate attribute ids!'
                print ('%s has id %d which is already defined in %s' % (obj.name,
                 obj.id,
                 glue_params[obj.id].name))
        else:
            glue_params[obj.id] = obj
    elif (type(obj) == type([])):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type({})):
        for o in obj.values():
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type(())):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)


Edit: this was decompiled with UruPython.

Re: Syntax error in glue code

PostPosted: Wed Jun 25, 2008 3:57 pm
by Branan
Mine were decompiled with PlasmaShop 2.2.4. Just did a decompile with UruPython, and it looks good. I'll have to remember not to use PlasmaShop for Python stuff, at least for now.