Skip to content

Commit f2f61df

Browse files
committed
refact: add __iter__ protocol
1 parent ec25a6a commit f2f61df

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/symbols/arglist.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#!/usr/bin/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)
76
#
87
# This program is Free Software and is released under the terms of
98
# the GNU General License
109
# ----------------------------------------------------------------------
10+
from __future__ import annotations
11+
12+
from typing import Iterable
1113

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
@@ -42,15 +44,17 @@ def __repr__(self):
4244
def __len__(self):
4345
return len(self.args)
4446

47+
def __iter__(self):
48+
return iter(self.args)
49+
4550
@classmethod
46-
def make_node(cls, node, *args):
51+
def make_node(cls, node: SymbolARGLIST | None, *args: SymbolARGUMENT):
4752
"""This will return a node with an argument_list."""
4853
if node is None:
4954
node = cls()
5055

5156
assert isinstance(node, SymbolARGUMENT) or isinstance(node, cls)
52-
53-
if not isinstance(node, cls):
57+
if isinstance(node, SymbolARGUMENT):
5458
return cls.make_node(None, node, *args)
5559

5660
for arg in args:

src/symbols/paramlist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/usr/bin/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)
76
#
87
# This program is Free Software and is released under the terms of
98
# the GNU General License
109
# ----------------------------------------------------------------------
10+
from typing import Iterable
1111

1212
from src.symbols.id_.interface import SymbolIdABC as SymbolID
1313
from src.symbols.symbol_ import Symbol
1414

1515

16-
class SymbolPARAMLIST(Symbol):
16+
class SymbolPARAMLIST(Symbol, Iterable[SymbolID]):
1717
"""Defines a list of parameters definitions in a function header"""
1818

1919
def __init__(self, *params):

0 commit comments

Comments
 (0)