Skip to content

Commit

Permalink
thrift: remove defaults for required arguments in generated init
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsudip committed May 29, 2020
1 parent 8d2e8e1 commit 5617a55
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions thriftpy2/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5617a55

Please sign in to comment.