11# pyre-strict
2+ from __future__ import annotations
3+
24import gzip
35import json
46import logging
57import os
68import pickle
79from io import BytesIO
8- from typing import Any , BinaryIO , Dict , List , Optional , Tuple
10+ from typing import Any , BinaryIO , Dict , List , Optional , Tuple , TYPE_CHECKING
911
1012import numpy as np
1113from numpy .typing import NDArray
1214from opensfm import config , features , geo , io , masking , pygeometry , pymap , rig , types
1315from opensfm .dataset_base import DataSetBase
1416from PIL .PngImagePlugin import PngImageFile
1517
18+ if TYPE_CHECKING :
19+ from collections .abc import Callable
20+ from types import ModuleType
21+
1622logger : logging .Logger = logging .getLogger (__name__ )
1723
1824
@@ -348,11 +354,11 @@ def load_matches(self, image: str) -> Dict[str, NDArray]:
348354 # than the numpy ones we allow.
349355 class MatchingUnpickler (pickle .Unpickler ):
350356 # Handle both numpy <2.0 (np.core) and numpy >=2.0 (np._core)
351- _multiarray = (
357+ _multiarray : ModuleType = (
352358 # pyrefly: ignore [missing-attribute]
353359 np .core .multiarray if hasattr (np , "core" ) else np ._core .multiarray
354360 )
355- modules_map = {
361+ modules_map : dict [ str , ModuleType ] = {
356362 "numpy.core.multiarray._reconstruct" : _multiarray ,
357363 "numpy.core.multiarray.scalar" : _multiarray ,
358364 "numpy._core.multiarray._reconstruct" : _multiarray ,
@@ -361,7 +367,9 @@ class MatchingUnpickler(pickle.Unpickler):
361367 "numpy.dtype" : np ,
362368 }
363369
364- def find_class (self , module , name ):
370+ def find_class (
371+ self , module : str , name : str
372+ ) -> type [object ] | Callable [..., object ]:
365373 classname = f"{ module } .{ name } "
366374 allowed_module = classname in self .modules_map
367375 if not allowed_module :
0 commit comments