From 4e8d40bc64262cd4566b06ff66b54271eefb5758 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Thu, 8 Aug 2024 15:06:55 +0300 Subject: [PATCH] fucking stupid tuping --- cantok/tokens/abstract/abstract_token.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cantok/tokens/abstract/abstract_token.py b/cantok/tokens/abstract/abstract_token.py index 4261612..184c2a5 100644 --- a/cantok/tokens/abstract/abstract_token.py +++ b/cantok/tokens/abstract/abstract_token.py @@ -1,7 +1,8 @@ +import sys from sys import getrefcount from abc import ABC, abstractmethod from threading import RLock -from typing import List, Dict, Awaitable, Optional, Union, Any +from typing import TypeAlias, List, Dict, Awaitable, Optional, Union, Any from collections.abc import Iterable from cantok.errors import CancellationError @@ -10,6 +11,11 @@ from cantok.tokens.abstract.coroutine_wrapper import WaitCoroutineWrapper +if sys.version_info >= (3, 8): + IterableWithTokens: TypeAlias = Iterable['AbstractToken'] # pragma: no cover +else: + IterableWithTokens = Iterable # pragma: no cover + class AbstractToken(ABC): exception = CancellationError rollback_if_nondirect_polling = False @@ -79,7 +85,7 @@ def __add__(self, item: 'AbstractToken') -> 'AbstractToken': def __bool__(self) -> bool: return self.keep_on() - def filter_tokens(self, tokens: Iterable['AbstractToken']) -> List['AbstractToken']: + def filter_tokens(self, tokens: IterableWithTokens) -> List['AbstractToken']: from cantok import DefaultToken result: List[AbstractToken] = []