def get_segments(
        self,
        traits: typing.List[Trait] = None,  # type: ignore[assignment]
        overrides_only: bool = False,
    ) -> typing.List[Segment]:
        """
        Get the list of segments this identity is a part of.

        :param traits: override the identity's traits when evaluating segments
        :param overrides_only: only retrieve the segments which have a valid override in the environment
        :return: List of matching segments
        """
        matching_segments = []
        traits = (
            self.identity_traits.all() if (traits is None and self.id) else traits or []
        )

        if overrides_only:
            all_segments = self.environment.get_segments_from_cache()
        else:
            all_segments = self.environment.project.get_segments_from_cache()

        engine_identity = map_identity_to_engine(
            self,
            with_overrides=False,
            with_traits=False,
        )
        engine_traits = map_traits_to_engine(traits)

        for segment in all_segments:
            engine_segment = map_segment_to_engine(segment)

            if evaluate_identity_in_segment(
                identity=engine_identity,
                segment=engine_segment,
                override_traits=engine_traits,
            ):
                matching_segments.append(segment)

        return matching_segments

        Get the list of segments this identity is a part of.

        :param traits: override the identity's traits when evaluating segments
        :param overrides_only: only retrieve the segments which have a valid override in the environment
        :return: List of matching segments
        
api/environments/identities/models.py