# https://github.com/python/typing/issues/59#issuecomment-353878355
# https://gitea.fxreader.online/fxreader.online/freelance-project-34-marketing-blog/issues/2#issue-25

import typing
from typing import Any, TypeVar, Optional, Iterable, Sequence, cast
from typing_extensions import Protocol
from abc import abstractmethod

C = typing.TypeVar('C', bound='Comparable')


class Comparable(Protocol):
	@abstractmethod
	def __eq__(self, other: Any) -> bool:
		pass

	@abstractmethod
	def __lt__(self: C, other: C) -> bool:
		pass

	def __gt__(self: C, other: C) -> bool:
		return (not self < other) and self != other

	def __le__(self: C, other: C) -> bool:
		return self < other or self == other

	def __ge__(self: C, other: C) -> bool:
		return not self < other


T = TypeVar('T', bound='Iterable[Any] | Sequence[Any]')


def check_generic(o: Any, t: type[T]) -> T:
	res = cast(T, o)

	assert isinstance(o, t)

	return res
