Add Python type hints to attributes of TL types (#678)

This commit is contained in:
Tulir Asokan
2018-03-12 11:58:56 +02:00
committed by Lonami
parent 751461f0f5
commit 935de0afbb
4 changed files with 99 additions and 6 deletions

View File

@@ -254,7 +254,7 @@ class TLArg:
self.generic_definition = generic_definition
def type_hint(self):
def doc_type_hint(self):
result = {
'int': 'int',
'long': 'int',
@@ -272,6 +272,27 @@ class TLArg:
return result
def python_type_hint(self):
type = self.type
if '.' in type:
type = type.split('.')[1]
result = {
'int': 'int',
'long': 'int',
'int128': 'int',
'int256': 'int',
'string': 'str',
'date': 'Optional[datetime]', # None date = 0 timestamp
'bytes': 'bytes',
'true': 'bool',
}.get(type, "Type{}".format(type))
if self.is_vector:
result = 'List[{}]'.format(result)
if self.is_flag and type != 'date':
result = 'Optional[{}]'.format(result)
return result
def __str__(self):
# Find the real type representation by updating it as required
real_type = self.type