Skip to content

Commit

Permalink
thrift: treat required fields as positional arguments while generatin…
Browse files Browse the repository at this point in the history
…g init, closes Thriftpy#119
  • Loading branch information
iamsudip committed May 28, 2020
1 parent b981e8c commit 741412c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions thriftpy2/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,23 @@ def __init__(self):
pass
return __init__

varnames, defaults = zip(*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[2]:
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)

args = ', '.join(map('{0[0]}={0[1]!r}'.format, spec))
init = "def __init__(self, {}):\n".format(args)
init += "\n".join(map(' self.{0} = {0}'.format, varnames))

Expand Down

0 comments on commit 741412c

Please sign in to comment.