|
32 | 32 |
|
33 | 33 | PSEUDO_KEY_TYPES = {'String', 'Int', 'Float', 'Bool'}
|
34 | 34 |
|
35 |
| -BUILTIN_FUNCTIONS = {'print', 'input', 'str', 'int', 'len', 'any', 'all', 'sum'} |
| 35 | +BUILTIN_FUNCTIONS = {'print', 'input', 'str', 'set', 'int', 'len', 'any', 'all', 'sum'} |
36 | 36 |
|
37 | 37 | FORBIDDEN_TOP_LEVEL_FUNCTIONS = {'map', 'filter'}
|
38 | 38 |
|
@@ -411,7 +411,18 @@ def _translate_call(self, func, args, keywords, starargs=None, kwargs=None, loca
|
411 | 411 | }
|
412 | 412 |
|
413 | 413 | elif isinstance(func, ast.Name) and func.id in BUILTIN_FUNCTIONS:
|
414 |
| - if func.id in ['any', 'all', 'sum']: |
| 414 | + if func.id == 'set': |
| 415 | + if args: |
| 416 | + raise translation_error('only set() supported', |
| 417 | + location, self.lines[location[0]], |
| 418 | + suggestions='please use {} notation if a set has elements') |
| 419 | + return { |
| 420 | + 'type': 'set', |
| 421 | + 'pseudo_type': ['Set', None], |
| 422 | + 'elements': [] |
| 423 | + } |
| 424 | + |
| 425 | + elif func.id in ['any', 'all', 'sum']: |
415 | 426 | if len(args) != 1:
|
416 | 427 | raise translation_error('%s expected 1 arg, not %d' % (func.id, len(args)),
|
417 | 428 | location, self.lines[location[0]])
|
@@ -471,7 +482,6 @@ def _translate_call(self, func, args, keywords, starargs=None, kwargs=None, loca
|
471 | 482 | }],
|
472 | 483 | 'pseudo_type': _type
|
473 | 484 | }
|
474 |
| - |
475 | 485 | else:
|
476 | 486 | arg_nodes = self._translate_node(args)
|
477 | 487 | return self._translate_builtin_call('global', func.id, arg_nodes, location)
|
@@ -1216,6 +1226,12 @@ def _testable(self, test_node):
|
1216 | 1226 | 'message': 'has_match',
|
1217 | 1227 | 'args': []
|
1218 | 1228 | }
|
| 1229 | + elif t == 'Void': |
| 1230 | + return { |
| 1231 | + 'type': 'not_null_check', |
| 1232 | + 'value': test_node, |
| 1233 | + 'pseudo_type': 'Boolean' |
| 1234 | + } |
1219 | 1235 | else:
|
1220 | 1236 | raise PseudoPythonTypeCheckError('pseudo-python expects a bool or RegexpMatch test not %s' % serialize_type(test_node['pseudo_type']))
|
1221 | 1237 | else:
|
|
0 commit comments