44from collections .abc import Iterable
55from enum import Enum
66from pathlib import Path
7- from typing import Optional , TypeVar
7+ from typing import Generic , Optional , TypeVar , Union
88
99import attrs
1010from structlog import get_logger
@@ -255,7 +255,8 @@ def get_output_dir(self) -> Optional[Path]:
255255
256256
257257class _JSONEncoder (json .JSONEncoder ):
258- def default (self , obj ):
258+ def default (self , o ):
259+ obj = o
259260 if attrs .has (type (obj )):
260261 extend_attr_output = True
261262 attr_output = attrs .asdict (obj , recurse = not extend_attr_output )
@@ -438,7 +439,10 @@ def extract(self, paths: list[Path], outdir: Path) -> Optional[ExtractResult]:
438439 return self .EXTRACTOR .extract (paths , outdir )
439440
440441
441- class Handler (abc .ABC ):
442+ TExtractor = TypeVar ("TExtractor" , bound = Union [None , Extractor ])
443+
444+
445+ class Handler (abc .ABC , Generic [TExtractor ]):
442446 """A file type handler is responsible for searching, validating and "unblobbing" files from Blobs."""
443447
444448 NAME : str
@@ -447,12 +451,12 @@ class Handler(abc.ABC):
447451 # (e.g. tar magic is in the middle of the header)
448452 PATTERN_MATCH_OFFSET : int = 0
449453
450- EXTRACTOR : Optional [ Extractor ]
454+ EXTRACTOR : TExtractor
451455
452456 @classmethod
453457 def get_dependencies (cls ):
454458 """Return external command dependencies needed for this handler to work."""
455- if cls .EXTRACTOR :
459+ if cls .EXTRACTOR is not None :
456460 return cls .EXTRACTOR .get_dependencies ()
457461 return []
458462
0 commit comments