From 0b48b1ec8a13d020e2058bce522e3107a8848f59 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 23 Sep 2017 10:41:36 +0200 Subject: [PATCH] Add support for non-recursive TLObject.to_dict() --- telethon_generator/tl_generator.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/telethon_generator/tl_generator.py b/telethon_generator/tl_generator.py index 705710d4..30313411 100644 --- a/telethon_generator/tl_generator.py +++ b/telethon_generator/tl_generator.py @@ -265,7 +265,7 @@ class TLGenerator: # Write the to_dict(self) method if args: - builder.writeln('def to_dict(self):') + builder.writeln('def to_dict(self, recursive=True):') builder.writeln('return {') builder.current_indent += 1 @@ -285,13 +285,15 @@ class TLGenerator: else: if arg.is_vector: builder.write( - '[] if self.{0} is None else [None ' + '([] if self.{0} is None else [None ' 'if x is None else x.to_dict() for x in self.{0}]' + ') if recursive else self.{0}' .format(arg.name) ) else: builder.write( - 'None if self.{0} is None else self.{0}.to_dict()' + '(None if self.{0} is None else ' + 'self.{0}.to_dict()) if recursive else self.{0}' .format(arg.name) ) builder.writeln(',') @@ -299,8 +301,7 @@ class TLGenerator: builder.current_indent -= 1 builder.writeln("}") else: - builder.writeln('@staticmethod') - builder.writeln('def to_dict():') + builder.writeln('def to_dict(self, recursive=True):') builder.writeln('return {}') builder.end_block()