From 9b17888e3e9baa2a5cb6b19478042192b74c18b4 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 11 Jul 2017 11:36:00 +0200 Subject: [PATCH] Make generated code slightly smaller --- telethon_generator/tl_generator.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/telethon_generator/tl_generator.py b/telethon_generator/tl_generator.py index f7ab886f..c5bb4f3c 100644 --- a/telethon_generator/tl_generator.py +++ b/telethon_generator/tl_generator.py @@ -437,7 +437,7 @@ class TLGenerator: """ if arg.is_vector: builder.writeln( - 'self.{0} = [{1}({0}_item) for {0}_item in {0}]' + 'self.{0} = [{1}(_x) for _x in {0}]' .format(arg.name, get_input_code) ) pass @@ -504,11 +504,10 @@ class TLGenerator: "writer.write_int(0x1cb5c415, signed=False) # Vector's constructor ID") builder.writeln('writer.write_int(len({}))'.format(name)) - builder.writeln('for {}_item in {}:'.format(arg.name, name)) + builder.writeln('for _x in {}:'.format(name)) # Temporary disable .is_vector, not to enter this if again arg.is_vector = False - TLGenerator.write_onsend_code( - builder, arg, args, name='{}_item'.format(arg.name)) + TLGenerator.write_onsend_code(builder, arg, args, name='_x') arg.is_vector = True elif arg.flag_indicator: @@ -599,13 +598,12 @@ class TLGenerator: builder.writeln("reader.read_int() # Vector's constructor ID") builder.writeln('{} = [] # Initialize an empty list'.format(name)) - builder.writeln('{}_len = reader.read_int()'.format(arg.name)) - builder.writeln('for _ in range({}_len):'.format(arg.name)) + builder.writeln('_len = reader.read_int()') + builder.writeln('for _ in range(_len):') # Temporary disable .is_vector, not to enter this if again arg.is_vector = False - TLGenerator.write_onresponse_code( - builder, arg, args, name='{}_item'.format(arg.name)) - builder.writeln('{}.append({}_item)'.format(name, arg.name)) + TLGenerator.write_onresponse_code(builder, arg, args, name='_x') + builder.writeln('{}.append(_x)'.format(name)) arg.is_vector = True elif arg.flag_indicator: @@ -620,12 +618,14 @@ class TLGenerator: builder.writeln('{} = reader.read_long()'.format(name)) elif 'int128' == arg.type: - builder.writeln('{} = reader.read_large_int(bits=128)'.format( - name)) + builder.writeln( + '{} = reader.read_large_int(bits=128)'.format(name) + ) elif 'int256' == arg.type: - builder.writeln('{} = reader.read_large_int(bits=256)'.format( - name)) + builder.writeln( + '{} = reader.read_large_int(bits=256)'.format(name) + ) elif 'double' == arg.type: builder.writeln('{} = reader.read_double()'.format(name))