mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Import os only once on the generated code
This commit is contained in:
parent
2c5c674531
commit
2595d45bd7
|
@ -137,13 +137,17 @@ class TLGenerator:
|
||||||
x for x in namespace_tlobjects.keys() if x
|
x for x in namespace_tlobjects.keys() if x
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
builder.writeln('import os')
|
||||||
|
|
||||||
# Generate the class for every TLObject
|
# Generate the class for every TLObject
|
||||||
for t in sorted(tlobjects, key=lambda x: x.name):
|
for t in sorted(tlobjects, key=lambda x: x.name):
|
||||||
TLGenerator._write_source_code(
|
TLGenerator._write_source_code(
|
||||||
t, builder, depth, type_constructors
|
t, builder, depth, type_constructors
|
||||||
)
|
)
|
||||||
while builder.current_indent != 0:
|
builder.current_indent = 0
|
||||||
builder.end_block()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _write_source_code(tlobject, builder, depth, type_constructors):
|
def _write_source_code(tlobject, builder, depth, type_constructors):
|
||||||
|
@ -170,10 +174,6 @@ class TLGenerator:
|
||||||
builder.writeln('from {}.utils import {}'.format(
|
builder.writeln('from {}.utils import {}'.format(
|
||||||
'.' * depth, ', '.join(util_imports)))
|
'.' * depth, ', '.join(util_imports)))
|
||||||
|
|
||||||
if any(a for a in tlobject.args if a.can_be_inferred):
|
|
||||||
# Currently only 'random_id' needs 'os' to be imported
|
|
||||||
builder.writeln('import os')
|
|
||||||
|
|
||||||
builder.writeln()
|
builder.writeln()
|
||||||
builder.writeln()
|
builder.writeln()
|
||||||
builder.writeln('class {}(TLObject):'.format(
|
builder.writeln('class {}(TLObject):'.format(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user