Support for the new in python 3.8 Constant ast node

This commit is contained in:
Kovid Goyal 2020-11-25 12:55:38 +05:30
parent 66a4ec4738
commit 72308168ef
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -185,6 +185,8 @@ def convert_node(fields, x, names={}, import_data=None):
elif name == 'BinOp': elif name == 'BinOp':
if x.right.__class__.__name__ == 'Str': if x.right.__class__.__name__ == 'Str':
return x.right.s.decode('utf-8') if isinstance(x.right.s, bytes) else x.right.s return x.right.s.decode('utf-8') if isinstance(x.right.s, bytes) else x.right.s
if x.right.__class__.__name__ == 'Constant' and isinstance(x.right.value, str):
return x.right.value
elif name == 'Attribute': elif name == 'Attribute':
return conv(getattr(conv(x.value), x.attr)) return conv(getattr(conv(x.value), x.attr))
raise TypeError('Unknown datatype %s for fields: %s' % (x, fields)) raise TypeError('Unknown datatype %s for fields: %s' % (x, fields))