Debian Codegraph @

lib/ansible/_internal/_collection_proxy.py

raw
1 from __future__ import annotations as _annotations
2
3 import collections.abc as _c
4 import typing as _t
5
6
7 class SequenceProxy[T](_c.Sequence[T]):
8 """A read-only sequence proxy."""
9
10 # DTFIX5: needs unit test coverage
11
12 __slots__ = ('__value',)
13
14 def __init__(self, value: _c.Sequence[T]) -> None:
15 self.__value = value
16
17 @_t.overload
18 def __getitem__(self, index: int) -> T: ...
19
20 @_t.overload
21 def __getitem__(self, index: slice) -> _c.Sequence[T]: ...
22
23 def __getitem__(self, index: int | slice) -> T | _c.Sequence[T]:
24 if isinstance(index, slice):
25 return self.__class__(self.__value[index])
26
27 return self.__value[index]
28
29 def __len__(self) -> int:
30 return len(self.__value)
31
32 def __contains__(self, item: object) -> bool:
33 return item in self.__value
34
35 def __iter__(self) -> _t.Iterator[T]:
36 yield from self.__value
37
38 def __reversed__(self) -> _c.Iterator[T]:
39 return reversed(self.__value)
40
41 def index(self, *args) -> int:
42 return self.__value.index(*args)
43
44 def count(self, value: object) -> int:
45 return self.__value.count(value)