From bc7ecd5d40da3cb8fb48a937d2303923dce2d760 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Tue, 1 Jul 2025 15:24:10 +0300 Subject: [PATCH] [+] partially add check_generic --- .../online/fxreader/pr34/commands_typed/typing.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/python/online/fxreader/pr34/commands_typed/typing.py b/python/online/fxreader/pr34/commands_typed/typing.py index 66011df..0ca727e 100644 --- a/python/online/fxreader/pr34/commands_typed/typing.py +++ b/python/online/fxreader/pr34/commands_typed/typing.py @@ -2,7 +2,7 @@ # https://gitea.fxreader.online/fxreader.online/freelance-project-34-marketing-blog/issues/2#issue-25 import typing -from typing import Any +from typing import Any, TypeVar, Optional, Iterable, Sequence from typing_extensions import Protocol from abc import abstractmethod @@ -26,3 +26,15 @@ class Comparable(Protocol): 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[Any], o) + + assert isinstance(o, t) + + return res