diff --git a/thriftpy2/thrift.py b/thriftpy2/thrift.py index a409e56c..92cbb8fc 100644 --- a/thriftpy2/thrift.py +++ b/thriftpy2/thrift.py @@ -68,20 +68,24 @@ def __init__(self): pass return __init__ - - varnames, defaults = zip(*spec) if hasattr(cls, 'thrift_spec'): args = [] kwargs = [] + varnames = [] + defaults = [] for spec_element, t_spec in zip(spec, cls.thrift_spec.values()): + varnames.append(spec_element[0]) if t_spec[-1]: args.append(spec_element[0]) else: kwargs.append(spec_element) + defaults.append(spec_element[1]) + defaults = tuple(defaults) if defaults else None args.extend(map('{0[0]}={0[1]!r}'.format, kwargs)) args = ', '.join(args) else: + varnames, defaults = zip(*spec) args = ', '.join(map('{0[0]}={0[1]!r}'.format, spec)) init = "def __init__(self, {}):\n".format(args)