wibiti/uncompyle2 — Issue #11: Decompiled code improvement suggestions
Author: bloodyshade
Created: 2012-02-17 17:52:42+00:00
State: open

Not a bug but some things I noticed with the decompiled code.

Plenty of elifs are removed, which can result in big cascades of if/else code, below is an example, though nothing really big:

def nice_repr(v):
if isinstance(v, (types.ClassType, type)):
return v.__module__ + '.' + v.__name__
else:
if isinstance(v, types.FunctionType):
if '__name__' in v.func_globals:
if getattr(sys.modules[v.func_globals['__name__']], v.func_name, None) is v:
return '%s.%s' % (v.func_globals['__name__'], v.func_name)
return repr(v)
if isinstance(v, types.MethodType):
return '%s.%s of %s' % (nice_repr(v.im_class), v.im_func.func_name, nice_repr(v.im_self))
return repr(v)

instead of

def nice_repr(v):
if isinstance(v, (types.ClassType, type)):
return v.__module__ + '.' + v.__name__
elif isinstance(v, types.FunctionType):
if '__name__' in v.func_globals:
if getattr(sys.modules[v.func_globals['__name__']],
v.func_name, None) is v:
return '%s.%s' % (v.func_globals['__name__'], v.func_name)
return repr(v)
elif isinstance(v, types.MethodType):
return '%s.%s of %s' % (
nice_repr(v.im_class), v.im_func.func_name,
nice_repr(v.im_self))
else:
return repr(v)

I also noticed it puts the vars in multi-var assignment and multi-var loops in a tuple, doesn't really look good

for (bin, points,) in self.bins.items():
#another one
for r in cursor.fetchall():
(name, xpPrimary, xpSecondary, xpTertiary, playerID,) = r

instead of

for bin, points in self.bins.items():
#another one
for r in cursor.fetchall():
name, xpPrimary, xpSecondary, xpTertiary, playerID = r

And the last thing I noticed and I think is particularly bad, is the use of dict.has_key instead of the 'in' keyword

if COMMANDS.has_key(cmd):

instead of

if cmd in COMMANDS:

Please don't take it as an offense, I know how much work you put in uncompyle2 and that's exactly why I decided to report this, because I believe it can become even better!

Best regards,
Luis Henrique.