From b40708a8c76dad773f8a171bc5f4617714173d72 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 25 Sep 2017 14:05:13 +0200 Subject: [PATCH] Import get_input_* only once on the generated code --- telethon_generator/tl_generator.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/telethon_generator/tl_generator.py b/telethon_generator/tl_generator.py index 6455d3a4..bb9796aa 100644 --- a/telethon_generator/tl_generator.py +++ b/telethon_generator/tl_generator.py @@ -136,6 +136,15 @@ class TLGenerator: x for x in namespace_tlobjects.keys() if x ))) + # Import 'get_input_*' utils + # TODO Support them on types too + if 'functions' in out_dir: + builder.writeln( + 'from {}.utils import get_input_peer, ' + 'get_input_channel, get_input_user, ' + 'get_input_media'.format('.' * depth) + ) + # Import 'os' for those needing access to 'os.urandom()' # Currently only 'random_id' needs 'os' to be imported, # for all those TLObjects with arg.can_be_inferred. @@ -157,24 +166,6 @@ class TLGenerator: the Type: [Constructors] must be given for proper importing and documentation strings. """ - if tlobject.is_function: - util_imports = set() - for a in tlobject.args: - # We can automatically convert some "full" types to - # "input only" (like User -> InputPeerUser, etc.) - if a.type == 'InputPeer': - util_imports.add('get_input_peer') - elif a.type == 'InputChannel': - util_imports.add('get_input_channel') - elif a.type == 'InputUser': - util_imports.add('get_input_user') - elif a.type == 'InputMedia': - util_imports.add('get_input_media') - - if util_imports: - builder.writeln('from {}.utils import {}'.format( - '.' * depth, ', '.join(util_imports))) - builder.writeln() builder.writeln() builder.writeln('class {}(TLObject):'.format(tlobject.class_name()))