Skip to content

Commit

Permalink
check cancel status of tokens before all when doing sum
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Aug 8, 2024
1 parent 506a55c commit ab318ae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cantok/tokens/abstract/abstract_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __add__(self, item: 'AbstractToken') -> 'AbstractToken':

from cantok import SimpleToken, DefaultToken, TimeoutToken

if self._cancelled or item._cancelled:
return SimpleToken(cancelled=True)

nested_tokens = []
container_token: Optional[AbstractToken] = None

Expand All @@ -79,9 +82,7 @@ def __add__(self, item: 'AbstractToken') -> 'AbstractToken':
return self

for token in self, item:
if token._cancelled:
return SimpleToken(cancelled=True)
elif isinstance(token, SimpleToken) and getrefcount(token) < 6:
if isinstance(token, SimpleToken) and getrefcount(token) < 6:
nested_tokens.extend(token.tokens)
elif isinstance(token, DefaultToken):
pass
Expand Down

0 comments on commit ab318ae

Please sign in to comment.