Skip to content

Commit d435eff

Browse files
authored
chore: upgrade types (#741)
* git rm -r mapillary_tools/video_data_extraction/ * upgrade types with prompt: Update types with the following rules: 1. Relace T.Optional with | and T.List with list, and so on 2. Keep compatible with Python>=3.8 3. Do no use `from typing import ?`. Instead, always use `import typing as T` * fix ruff check * fix tests for 3.8 * integration tests for python3.8
1 parent dd51762 commit d435eff

37 files changed

+366
-1153
lines changed

mapillary_tools/api_v4.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _log_debug_response(resp: requests.Response):
135135
if logging.getLogger().getEffectiveLevel() <= logging.DEBUG:
136136
return
137137

138-
data: T.Union[str, bytes]
138+
data: str | bytes
139139
try:
140140
data = _truncate(dumps(_sanitize(resp.json())))
141141
except Exception:
@@ -148,7 +148,7 @@ def readable_http_error(ex: requests.HTTPError) -> str:
148148
req = ex.request
149149
resp = ex.response
150150

151-
data: T.Union[str, bytes]
151+
data: str | bytes
152152
try:
153153
data = _truncate(dumps(_sanitize(resp.json())))
154154
except Exception:
@@ -284,7 +284,7 @@ def get_upload_token(email: str, password: str) -> requests.Response:
284284

285285

286286
def fetch_organization(
287-
user_access_token: str, organization_id: T.Union[int, str]
287+
user_access_token: str, organization_id: int | str
288288
) -> requests.Response:
289289
resp = request_get(
290290
f"{MAPILLARY_GRAPH_API_ENDPOINT}/{organization_id}",
@@ -329,7 +329,7 @@ def fetch_user_or_me(
329329
]
330330

331331

332-
def log_event(action_type: ActionType, properties: T.Dict) -> requests.Response:
332+
def log_event(action_type: ActionType, properties: dict) -> requests.Response:
333333
resp = request_post(
334334
f"{MAPILLARY_GRAPH_API_ENDPOINT}/logging",
335335
json={

mapillary_tools/camm/camm_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def serialize(cls, data: telemetry.MagnetometerData) -> bytes:
373373
assert len(SAMPLE_ENTRY_CLS_BY_CAMM_TYPE) == 5, SAMPLE_ENTRY_CLS_BY_CAMM_TYPE.keys()
374374

375375

376-
_SWITCH: T.Dict[int, C.Struct] = {
376+
_SWITCH: dict[int, C.Struct] = {
377377
# Angle_axis
378378
CAMMType.ANGLE_AXIS.value: _Float[3], # type: ignore
379379
# Exposure time
@@ -436,7 +436,7 @@ def _parse_telemetry_from_sample(
436436

437437
def _filter_telemetry_by_elst_segments(
438438
measurements: T.Iterable[TelemetryMeasurement],
439-
elst: T.Sequence[T.Tuple[float, float]],
439+
elst: T.Sequence[tuple[float, float]],
440440
) -> T.Generator[TelemetryMeasurement, None, None]:
441441
empty_elst = [entry for entry in elst if entry[0] == -1]
442442
if empty_elst:
@@ -466,8 +466,8 @@ def _filter_telemetry_by_elst_segments(
466466

467467

468468
def elst_entry_to_seconds(
469-
entry: T.Dict, movie_timescale: int, media_timescale: int
470-
) -> T.Tuple[float, float]:
469+
entry: dict, movie_timescale: int, media_timescale: int
470+
) -> tuple[float, float]:
471471
assert movie_timescale > 0, "expected positive movie_timescale"
472472
assert media_timescale > 0, "expected positive media_timescale"
473473
media_time, duration = entry["media_time"], entry["segment_duration"]
@@ -477,7 +477,7 @@ def elst_entry_to_seconds(
477477
return (media_time, duration)
478478

479479

480-
def _is_camm_description(description: T.Dict) -> bool:
480+
def _is_camm_description(description: dict) -> bool:
481481
return description["format"] == b"camm"
482482

483483

mapillary_tools/commands/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import enum
33
import logging
44
import sys
5-
import typing as T
65
from pathlib import Path
76

87
import requests
@@ -86,7 +85,7 @@ def configure_logger(logger: logging.Logger, stream=None) -> None:
8685
logger.addHandler(handler)
8786

8887

89-
def _log_params(argvars: T.Dict) -> None:
88+
def _log_params(argvars: dict) -> None:
9089
MAX_ENTRIES = 5
9190

9291
def _stringify(x) -> str:

mapillary_tools/config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import configparser
24
import os
35
import typing as T
@@ -35,8 +37,8 @@ def _load_config(config_path: str) -> configparser.ConfigParser:
3537

3638

3739
def load_user(
38-
profile_name: str, config_path: T.Optional[str] = None
39-
) -> T.Optional[types.UserItem]:
40+
profile_name: str, config_path: str | None = None
41+
) -> types.UserItem | None:
4042
if config_path is None:
4143
config_path = MAPILLARY_CONFIG_PATH
4244
config = _load_config(config_path)
@@ -46,7 +48,7 @@ def load_user(
4648
return T.cast(types.UserItem, user_items)
4749

4850

49-
def list_all_users(config_path: T.Optional[str] = None) -> T.Dict[str, types.UserItem]:
51+
def list_all_users(config_path: str | None = None) -> dict[str, types.UserItem]:
5052
if config_path is None:
5153
config_path = MAPILLARY_CONFIG_PATH
5254
cp = _load_config(config_path)
@@ -58,7 +60,7 @@ def list_all_users(config_path: T.Optional[str] = None) -> T.Dict[str, types.Use
5860

5961

6062
def update_config(
61-
profile_name: str, user_items: types.UserItem, config_path: T.Optional[str] = None
63+
profile_name: str, user_items: types.UserItem, config_path: str | None = None
6264
) -> None:
6365
if config_path is None:
6466
config_path = MAPILLARY_CONFIG_PATH
@@ -72,7 +74,7 @@ def update_config(
7274
config.write(fp)
7375

7476

75-
def remove_config(profile_name: str, config_path: T.Optional[str] = None) -> None:
77+
def remove_config(profile_name: str, config_path: str | None = None) -> None:
7678
if config_path is None:
7779
config_path = MAPILLARY_CONFIG_PATH
7880

mapillary_tools/constants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import os
4-
import typing as T
54

65
import appdirs
76

@@ -52,7 +51,7 @@ def _yes_or_no(val: str) -> bool:
5251
# It is used to filter out noisy points
5352
GOPRO_MAX_DOP100 = int(os.getenv(_ENV_PREFIX + "GOPRO_MAX_DOP100", 1000))
5453
# Within the GPS stream: 0 - no lock, 2 or 3 - 2D or 3D Lock
55-
GOPRO_GPS_FIXES: T.Set[int] = set(
54+
GOPRO_GPS_FIXES: set[int] = set(
5655
int(fix) for fix in os.getenv(_ENV_PREFIX + "GOPRO_GPS_FIXES", "2,3").split(",")
5756
)
5857
MAX_UPLOAD_RETRIES: int = int(os.getenv(_ENV_PREFIX + "MAX_UPLOAD_RETRIES", 200))

0 commit comments

Comments
 (0)