Skip to content

Commit b189e56

Browse files
committed
Fix set and not_null_check
1 parent 705c818 commit b189e56

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66

77
* Fix unary op handling
88
* Convert ** to `math:pow`
9-

pseudo_python/ast_translator.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
PSEUDO_KEY_TYPES = {'String', 'Int', 'Float', 'Bool'}
3434

35-
BUILTIN_FUNCTIONS = {'print', 'input', 'str', 'int', 'len', 'any', 'all', 'sum'}
35+
BUILTIN_FUNCTIONS = {'print', 'input', 'str', 'set', 'int', 'len', 'any', 'all', 'sum'}
3636

3737
FORBIDDEN_TOP_LEVEL_FUNCTIONS = {'map', 'filter'}
3838

@@ -411,7 +411,18 @@ def _translate_call(self, func, args, keywords, starargs=None, kwargs=None, loca
411411
}
412412

413413
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']:
415426
if len(args) != 1:
416427
raise translation_error('%s expected 1 arg, not %d' % (func.id, len(args)),
417428
location, self.lines[location[0]])
@@ -471,7 +482,6 @@ def _translate_call(self, func, args, keywords, starargs=None, kwargs=None, loca
471482
}],
472483
'pseudo_type': _type
473484
}
474-
475485
else:
476486
arg_nodes = self._translate_node(args)
477487
return self._translate_builtin_call('global', func.id, arg_nodes, location)
@@ -1216,6 +1226,12 @@ def _testable(self, test_node):
12161226
'message': 'has_match',
12171227
'args': []
12181228
}
1229+
elif t == 'Void':
1230+
return {
1231+
'type': 'not_null_check',
1232+
'value': test_node,
1233+
'pseudo_type': 'Boolean'
1234+
}
12191235
else:
12201236
raise PseudoPythonTypeCheckError('pseudo-python expects a bool or RegexpMatch test not %s' % serialize_type(test_node['pseudo_type']))
12211237
else:

0 commit comments

Comments
 (0)