From 5617a5520686c767f96848a89c23704c3f599a04 Mon Sep 17 00:00:00 2001 From: iamsudip Date: Fri, 29 May 2020 16:26:40 +0530 Subject: [PATCH] thrift: remove defaults for required arguments in generated init --- thriftpy2/thrift.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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)