Skip to content

Commit 050c606

Browse files
committed
Fix typing annotations for python 3.8
Queue does not accept type annotations and the tests running pytest was failing with ``` python -m pytest ... opensfm/features_processing.py:19: in <module> ProcessQueue = queue.Queue[ E TypeError: 'type' object is not subscriptable ... ``` Similar problem for networkx EdgeView
1 parent 5e8b852 commit 050c606

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

opensfm/features_processing.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# pyre-unsafe
1+
# pyre-strict
22
import itertools
33
import logging
44
import math
55
import queue
66
import threading
7+
import sys
78
from timeit import default_timer as timer
89
from typing import Any, Dict, List, Optional, Tuple
910

@@ -16,6 +17,26 @@
1617
logger: logging.Logger = logging.getLogger(__name__)
1718

1819

20+
if sys.version_info >= (3, 9):
21+
ProcessQueue = queue.Queue[
22+
Optional[
23+
Tuple[str, "NDArray", Optional["NDArray"], Optional["NDArray"], DataSetBase, bool]
24+
]
25+
]
26+
else:
27+
ProcessQueue = queue.Queue
28+
29+
ProducerArgs = Tuple[
30+
ProcessQueue,
31+
DataSetBase,
32+
List[str],
33+
"Counter",
34+
int,
35+
bool,
36+
]
37+
ConsumerArgs = ProcessQueue
38+
39+
1940
def run_features_processing(data: DataSetBase, images: List[str], force: bool) -> None:
2041
"""Main entry point for running features extraction on a list of images."""
2142
default_queue_size = 10

opensfm/large/tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# pyre-unsafe
1+
# pyre-strict
2+
from __future__ import annotations
23
import itertools
34
import logging
45
from collections import namedtuple

0 commit comments

Comments
 (0)