From f833931381be7a2c650a5b62fb3d5e493858afc7 Mon Sep 17 00:00:00 2001 From: jesko Date: Thu, 28 Nov 2024 17:42:16 +0100 Subject: [PATCH] fixes type hints --- refinery/units/pattern/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/refinery/units/pattern/__init__.py b/refinery/units/pattern/__init__.py index 83d859e2a..b8278a44d 100644 --- a/refinery/units/pattern/__init__.py +++ b/refinery/units/pattern/__init__.py @@ -3,9 +3,11 @@ """ Pattern matching based extraction and substitution units. """ +from __future__ import annotations + import re -from typing import Iterable, Optional, Callable, Union, Tuple, ByteString, Dict +from typing import Iterable, Optional, Callable, Union, Tuple, ByteString, Dict, TYPE_CHECKING from itertools import islice from hashlib import blake2b @@ -13,6 +15,9 @@ from refinery.lib.argformats import regexp from refinery.units import Arg, Unit +if TYPE_CHECKING: + MT = Tuple[int, re.Match[bytes]] + class PatternExtractorBase(Unit, abstract=True): @@ -61,7 +66,7 @@ def matches(self, data: ByteString, pattern: Union[ByteString, re.Pattern]): start = a + match.start() * 2 yield start, match - def _prefilter(self, matches: Iterable[Tuple[int, re.Match[bytes]]]) -> Iterable[Tuple[int, re.Match[bytes]]]: + def _prefilter(self, matches: Iterable[MT]) -> Iterable[MT]: barrier = set() taken = 0 for offset, match in matches: @@ -78,7 +83,7 @@ def _prefilter(self, matches: Iterable[Tuple[int, re.Match[bytes]]]) -> Iterable if not self.args.longest and taken >= self.args.take: break - def _postfilter(self, matches: Iterable[Tuple[int, re.Match[bytes]]]) -> Iterable[Tuple[int, re.Match[bytes]]]: + def _postfilter(self, matches: Iterable[MT]) -> Iterable[MT]: result = matches if self.args.longest and self.args.take and self.args.take is not INF: try: @@ -94,7 +99,7 @@ def _postfilter(self, matches: Iterable[Tuple[int, re.Match[bytes]]]) -> Iterabl elif self.args.take: yield from islice(result, abs(self.args.take)) - def matchfilter(self, matches: Iterable[Tuple[int, re.Match[bytes]]]) -> Iterable[Tuple[int, re.Match[bytes]]]: + def matchfilter(self, matches: Iterable[MT]) -> Iterable[MT]: yield from self._postfilter(self._prefilter(matches)) def matches_filtered(