Skip to content

Commit 6981501

Browse files
committed
chore(models/Handler): fix reportIncompatibleVariableOverride lints
This check is currently turned off in our `basic` `typeCheckingMode` profile, but is enabled in the `standard` profile. Things done here: - made the type of `Handler.EXTRACTOR` covariant, so child-classes can further narrow its type Error: unblob/handlers/archive/cpio.py unblob/handlers/archive/cpio.py:413:5 - error: "EXTRACTOR" overrides symbol of same name in class "Handler"   Variable is mutable so its type is invariant     Override type "_CPIOExtractorBase" is not the same as base type "Extractor | None" (reportIncompatibleVariableOverride)
1 parent cb009cb commit 6981501

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

unblob/models.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections.abc import Iterable
55
from enum import Enum
66
from pathlib import Path
7-
from typing import Optional, TypeVar
7+
from typing import Generic, Optional, TypeVar, Union
88

99
import attrs
1010
from structlog import get_logger
@@ -439,7 +439,10 @@ def extract(self, paths: list[Path], outdir: Path) -> Optional[ExtractResult]:
439439
return self.EXTRACTOR.extract(paths, outdir)
440440

441441

442-
class Handler(abc.ABC):
442+
TExtractor = TypeVar("TExtractor", bound=Union[None, Extractor])
443+
444+
445+
class Handler(abc.ABC, Generic[TExtractor]):
443446
"""A file type handler is responsible for searching, validating and "unblobbing" files from Blobs."""
444447

445448
NAME: str
@@ -448,12 +451,12 @@ class Handler(abc.ABC):
448451
# (e.g. tar magic is in the middle of the header)
449452
PATTERN_MATCH_OFFSET: int = 0
450453

451-
EXTRACTOR: Optional[Extractor]
454+
EXTRACTOR: TExtractor
452455

453456
@classmethod
454457
def get_dependencies(cls):
455458
"""Return external command dependencies needed for this handler to work."""
456-
if cls.EXTRACTOR:
459+
if cls.EXTRACTOR is not None:
457460
return cls.EXTRACTOR.get_dependencies()
458461
return []
459462

0 commit comments

Comments
 (0)