diff options
Diffstat (limited to 'mesonbuild/interpreter/primitives/range.py')
-rw-r--r-- | mesonbuild/interpreter/primitives/range.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mesonbuild/interpreter/primitives/range.py b/mesonbuild/interpreter/primitives/range.py new file mode 100644 index 0000000..5eb5e03 --- /dev/null +++ b/mesonbuild/interpreter/primitives/range.py @@ -0,0 +1,38 @@ +# Copyright 2021 The Meson development team +# SPDX-license-identifier: Apache-2.0 +from __future__ import annotations + +import typing as T + +from ...interpreterbase import ( + MesonInterpreterObject, + IterableObject, + MesonOperator, + InvalidArguments, +) + +if T.TYPE_CHECKING: + from ...interpreterbase import SubProject + +class RangeHolder(MesonInterpreterObject, IterableObject): + def __init__(self, start: int, stop: int, step: int, *, subproject: 'SubProject') -> None: + super().__init__(subproject=subproject) + self.range = range(start, stop, step) + self.operators.update({ + MesonOperator.INDEX: self.op_index, + }) + + def op_index(self, other: int) -> int: + try: + return self.range[other] + except IndexError: + raise InvalidArguments(f'Index {other} out of bounds of range.') + + def iter_tuple_size(self) -> None: + return None + + def iter_self(self) -> T.Iterator[int]: + return iter(self.range) + + def size(self) -> int: + return len(self.range) |