Skip to content

Commit 238744c

Browse files
generatedunixname975288348396129meta-codesync[bot]
authored andcommitted
fbcode/mapillary/opensfm/opensfm/dataset.py
Reviewed By: caglarpir Differential Revision: D111585918 fbshipit-source-id: 2e287acf117045edd6d9cf4f412174903a19f2d9
1 parent b50d7f6 commit 238744c

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎opensfm/dataset.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# pyre-strict
2+
from __future__ import annotations
3+
24
import gzip
35
import json
46
import logging
57
import os
68
import pickle
79
from 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

1012
import numpy as np
1113
from numpy.typing import NDArray
1214
from opensfm import config, features, geo, io, masking, pygeometry, pymap, rig, types
1315
from opensfm.dataset_base import DataSetBase
1416
from PIL.PngImagePlugin import PngImageFile
1517

18+
if TYPE_CHECKING:
19+
from collections.abc import Callable
20+
from types import ModuleType
21+
1622
logger: 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

Comments
 (0)