mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Assert flag params with same flag index are all set/unset
This commit is contained in:
parent
a5ab49c707
commit
ce48c9752e
|
@ -301,6 +301,26 @@ class TLGenerator:
|
||||||
|
|
||||||
# Write the .to_bytes() function
|
# Write the .to_bytes() function
|
||||||
builder.writeln('def to_bytes(self):')
|
builder.writeln('def to_bytes(self):')
|
||||||
|
|
||||||
|
# Some objects require more than one flag parameter to be set
|
||||||
|
# at the same time. In this case, add an assertion.
|
||||||
|
repeated_args = defaultdict(list)
|
||||||
|
for arg in tlobject.args:
|
||||||
|
if arg.is_flag:
|
||||||
|
repeated_args[arg.flag_index].append(arg)
|
||||||
|
|
||||||
|
for args in repeated_args.values():
|
||||||
|
if len(args) > 1:
|
||||||
|
cnd1 = ('self.{} is None'.format(a.name) for a in args)
|
||||||
|
cnd2 = ('self.{} is not None'.format(a.name) for a in args)
|
||||||
|
builder.writeln(
|
||||||
|
"assert ({}) or ({}), '{} parameters must all "
|
||||||
|
"be None or neither be None'".format(
|
||||||
|
' and '.join(cnd1), ' and '.join(cnd2),
|
||||||
|
', '.join(a.name for a in args)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
builder.writeln("return b''.join((")
|
builder.writeln("return b''.join((")
|
||||||
builder.current_indent += 1
|
builder.current_indent += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user