<commit_before># stdlib
import sys
from typing import Any
from typing import Optional
from typing import Union

# third party
from google.protobuf.reflection import GeneratedProtocolMessageType

# syft relative
from ... import deserialize
from ... import serialize
from ...core.common import UID
from ...core.common.serde.serializable import bind_protobuf
from ...logger import traceback_and_raise
from ...proto.lib.python.slice_pb2 import Slice as Slice_PB
from .primitive_factory import PrimitiveFactory
from .primitive_factory import isprimitive
from .primitive_interface import PyPrimitive
from .types import SyPrimitiveRet


@bind_protobuf
class Slice(int, PyPrimitive):
    def __init__(
        self,
        start: Any = None,
        stop: Any = None,
        step: Any = None,
        id: Optional[UID] = None,
    ):
        if not start and not stop and not step:
            self.start = None
            self.stop = None
            self.step = None

        self._id: UID = id if id else UID()

    def __eq__(self, other: Any) -> SyPrimitiveRet:
        res = super().__eq__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __ge__(self, other: Any) -> SyPrimitiveRet:
        res = super().__ge__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __gt__(self, other: Any) -> SyPrimitiveRet:
        res = super().__gt__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __hash__(self) -> SyPrimitiveRet:
        res = super().__hash__()
        return PrimitiveFactory.generate_primitive(value=res)

    def __le__(self, other: Any) -> SyPrimitiveRet:
        res = super().__le__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __lt__(self, other: Any) -> SyPrimitiveRet:
        res = super().__lt__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __ne__(self, other: Any) -> SyPrimitiveRet:
        res = super().__ne__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __sizeof__(self) -> SyPrimitiveRet:
        res = super().__sizeof__()
        return PrimitiveFactory.generate_primitive(value=res)

    def __getitem__(self, key: Any) -> Union[SyPrimitiveRet, Any]:
        res = super().__getitem__(key)  # ignore = type
        if isprimitive(value=res):
            return PrimitiveFactory.generate_primitive(value=res)
        else:
            # we can have torch.Tensor and other types
            return res

    def copy(self) -> SyPrimitiveRet:
        res = super().copy()
        return PrimitiveFactory.generate_primitive(value=res)

    def getindices(
        self,
        length: Any = None,
        start: Optional[int] = None,
        stop: Optional[int] = None,
        step: Optional[int] = None,
    ) -> SyPrimitiveRet:
        if self.step is None:
            step = 1
        if not isinstance(step, int):
            traceback_and_raise(TypeError("expected integer type arguments for step"))
        else:
            step = step
        if self.start is None:
            start = length - 1 if step < 0 else 0
        if not isinstance(start, int):
            traceback_and_raise(TypeError("expected integer type arguments for start"))
        else:
            start = start
            if start < 0:
                start = start + length
        if self.stop is None:
            stop = -1 if step < 0 else length
        if not isinstance(stop, int):
            traceback_and_raise(TypeError("expected integer type arguments for stop"))
        else:
            stop = stop
            if stop < 0:
                stop = stop + length<commit_msg>changes<commit_after># stdlib
import sys
from typing import Any
from typing import Optional
from typing import Union

# third party
from google.protobuf.reflection import GeneratedProtocolMessageType

# syft relative
from ... import deserialize
from ... import serialize
from ...core.common import UID
from ...core.common.serde.serializable import bind_protobuf
from ...logger import traceback_and_raise
from ...proto.lib.python.slice_pb2 import Slice as Slice_PB
from .primitive_factory import PrimitiveFactory
from .primitive_factory import isprimitive
from .primitive_interface import PyPrimitive
from .types import SyPrimitiveRet


@bind_protobuf
class Slice(slice, PyPrimitive):
    def __init__(
        self,
        start: Any = None,
        stop: Any = None,
        step: Any = None,
        id: Optional[UID] = None,
    ):
        if not start and not stop and not step:
            self.start = None
            self.stop = None
            self.step = None
        #slice.__init__(self, start, stop, step)
        self._id: UID = id if id else UID()

    def __eq__(self, other: Any) -> SyPrimitiveRet:
        res = super().__eq__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __ge__(self, other: Any) -> SyPrimitiveRet:
        res = super().__ge__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __gt__(self, other: Any) -> SyPrimitiveRet:
        res = super().__gt__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __hash__(self) -> SyPrimitiveRet:
        res = super().__hash__()
        return PrimitiveFactory.generate_primitive(value=res)

    def __le__(self, other: Any) -> SyPrimitiveRet:
        res = super().__le__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __lt__(self, other: Any) -> SyPrimitiveRet:
        res = super().__lt__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __ne__(self, other: Any) -> SyPrimitiveRet:
        res = super().__ne__(other)
        return PrimitiveFactory.generate_primitive(value=res)

    def __sizeof__(self) -> SyPrimitiveRet:
        res = super().__sizeof__()
        return PrimitiveFactory.generate_primitive(value=res)

    def __getitem__(self, key: Union[int, slice]) -> Any:
        res = super().__getitem__(key)  # ignore = type
        if isprimitive(value=res):
            return PrimitiveFactory.generate_primitive(value=res)
        return res

    def copy(self) -> "Slice":
        res = super().copy()
        res._id = UID()
        return res

    def getindices(
        self,
        length: Any = None,
        start: Optional[int] = None,
        stop: Optional[int] = None,
        step: Optional[int] = None,
    ) -> SyPrimitiveRet:
        if self.step is None:
            step = 1
        if not isinstance(step, int):
            traceback_and_raise(TypeError("expected integer type arguments for step"))
        else:
            step = step
        if self.start is None:
            start = length - 1 if step < 0 else 0
        if not isinstance(start, int):
            traceback_and_raise(TypeError("expected integer type arguments for start"))
        else:
            start = start
            if start < 0:
                start = start + length
        if self.stop is None:
            stop = -1 if step < 0 else length
        if not isinstance(stop, int):
            traceback_and_raise(TypeError("expected integer type arguments for stop"))
        else:
            stop = stop
            if stop < 0:
                stop = stop + length
{'fraction_non_alphanumeric': 0.09105869445968184, 'fraction_numerical': 0.0024684585847504115, 'mean_word_length': 2.414325842696629, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3839768', 'n_tokens_mistral': 2031, 'n_tokens_neox': 2013, 'n_words': 597}