Skip to content

Commit 15025d8

Browse files
authored
Merge pull request #678 from boriel/refact/symbols
refact: make SymbolArglist an iterable
2 parents 47e5ff5 + 48f84c0 commit 15025d8

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

src/symbols/arglist.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
# ----------------------------------------------------------------------
1010
from __future__ import annotations
1111

12+
from collections.abc import Iterable
13+
1214
from src.symbols.argument import SymbolARGUMENT
1315
from src.symbols.symbol_ import Symbol
1416

1517

16-
class SymbolARGLIST(Symbol):
18+
class SymbolARGLIST(Symbol, Iterable[SymbolARGUMENT]):
1719
"""Defines a list of arguments in a function call or array access"""
1820

1921
@property
@@ -33,6 +35,9 @@ def __setitem__(self, range_, value: SymbolARGUMENT):
3335
assert isinstance(value, SymbolARGUMENT)
3436
self.children[range_] = value
3537

38+
def __iter__(self):
39+
return iter(self.args)
40+
3641
def __str__(self):
3742
return "(%s)" % (", ".join(str(x) for x in self.args))
3843

src/symbols/builtin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
# vim: ts=4:et:sw=4:
43

54
# ----------------------------------------------------------------------
65
# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel)

src/symbols/symbol_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Symbol(Ast):
2727
def __init__(self, *children):
2828
super().__init__()
2929
for child in children:
30-
assert isinstance(child, Symbol)
30+
assert isinstance(child, Symbol), f"{child} is not Symbol"
3131
self.append_child(child)
3232

3333
self._required_by: Counter = Counter() # Symbols that depends on this one

src/zxbc/zxbparser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# the GNU General License
1010
# ----------------------------------------------------------------------
1111

12-
import collections
1312
import math
1413
import sys
1514
from math import pi as PI
@@ -233,8 +232,9 @@ def make_builtin(lineno, fname, operands, func=None, type_=None):
233232
assert isinstance(operands, Symbol) or isinstance(operands, tuple) or isinstance(operands, list)
234233
# TODO: In the future, builtin functions will be implemented in an external library, like POINT or ATTR
235234
__DEBUG__('Creating BUILTIN "{}"'.format(fname), 1)
236-
if not isinstance(operands, collections.abc.Iterable):
235+
if not isinstance(operands, (list, tuple, set)):
237236
operands = [operands]
237+
238238
return sym.BUILTIN.make_node(lineno, fname, func, type_, *operands)
239239

240240

0 commit comments

Comments
 (0)