Automatically infer the value for 'random_id' parameters

This commit is contained in:
Lonami Exo
2017-06-11 19:16:59 +02:00
parent 3ed59d08e5
commit 1ca41b5854
4 changed files with 68 additions and 27 deletions

View File

@@ -78,6 +78,14 @@ class TLObject:
result=match.group(3),
is_function=is_function)
def sorted_args(self):
"""Returns the arguments properly sorted and ready to plug-in
into a Python's method header (i.e., flags and those which
can be inferred will go last so they can default =None)
"""
return sorted(self.args,
key=lambda x: x.is_flag or x.can_be_inferred)
def is_core_type(self):
"""Determines whether the TLObject is a "core type"
(and thus should be embedded in the generated code) or not"""
@@ -134,6 +142,12 @@ class TLArg:
self.is_flag = False
self.flag_index = -1
# Special case: some types can be inferred, which makes it
# less annoying to type. Currently the only type that can
# be inferred is if the name is 'random_id', to which a
# random ID will be assigned if left as None (the default)
self.can_be_inferred = name == 'random_id'
# The type can be an indicator that other arguments will be flags
if arg_type == '#':
self.flag_indicator = True