Skip to content

Commit d02251d

Browse files
committed
📌 fix: Fix typing issue
Signed-off-by: Saif Ul Islam <[email protected]>
1 parent 94ce1d8 commit d02251d

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Setup variables. Change as needed
2525
NAME = "mapillary"
26-
VERSION = "1.0.10"
26+
VERSION = "1.0.11"
2727
AUTHOR = "Christopher Beddow"
2828
AUTHOR_EMAIL = "[email protected]"
2929
LICENSE = "MIT"

src/mapillary/models/api/general.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# Package imports
1717
import mercantile
18-
from typing import Literal
18+
import typing
1919
from vt2geojson.tools import vt_bytes_to_geojson
2020

2121
# Local imports
@@ -51,8 +51,12 @@ class GeneralAdapter(object):
5151
"""
5252

5353
# layer types
54-
__LAYER_TYPES = Literal[
55-
"overview", "sequence", "image", "map_feature", "traffic_sign"
54+
__LAYER_TYPES: typing.List[str] = [
55+
"overview",
56+
"sequence",
57+
"image",
58+
"map_feature",
59+
"traffic_sign",
5660
]
5761

5862
def __init__(self, *args: object) -> None:
@@ -73,7 +77,7 @@ def fetch_image_tiles(
7377
zoom: int,
7478
longitude: float,
7579
latitude: float,
76-
layer: __LAYER_TYPES = "image",
80+
layer: str = "image",
7781
) -> dict:
7882
"""
7983
Get the tiles for a given image.
@@ -93,7 +97,6 @@ def fetch_image_tiles(
9397

9498
# Perform validation checks
9599
self.__validation_checks(
96-
function=self.fetch_image_tiles,
97100
zoom=zoom,
98101
longitude=longitude,
99102
latitude=latitude,
@@ -114,7 +117,7 @@ def fetch_computed_image_tiles(
114117
zoom: int,
115118
longitude: float,
116119
latitude: float,
117-
layer: __LAYER_TYPES = "image",
120+
layer: str = "image",
118121
) -> dict:
119122
"""
120123
Get the image type for a given image.
@@ -133,7 +136,6 @@ def fetch_computed_image_tiles(
133136
"""
134137
# Perform validation checks
135138
self.__validation_checks(
136-
function=self.fetch_computed_image_tiles,
137139
zoom=zoom,
138140
longitude=longitude,
139141
latitude=latitude,
@@ -155,7 +157,7 @@ def fetch_map_features_tiles(
155157
zoom: int,
156158
longitude: float,
157159
latitude: float,
158-
layer: __LAYER_TYPES = "image",
160+
layer: str = "image",
159161
):
160162
"""
161163
Get the map features for a given coordinate set
@@ -174,7 +176,6 @@ def fetch_map_features_tiles(
174176
"""
175177
# Perform validation checks
176178
self.__validation_checks(
177-
function=self.fetch_map_features_tiles,
178179
zoom=zoom,
179180
longitude=longitude,
180181
latitude=latitude,
@@ -210,7 +211,6 @@ def fetch_map_features_traffic_tiles(
210211
"""
211212
# Perform validation checks
212213
self.__validation_checks(
213-
function=self.fetch_map_features_traffic_tiles,
214214
zoom=zoom,
215215
longitude=longitude,
216216
latitude=latitude,
@@ -241,7 +241,7 @@ def __preprocess_layer(
241241
)
242242

243243
return vt_bytes_to_geojson(
244-
# Paramaters appropriately
244+
# Parameters appropriately
245245
b_content=self.client.get(
246246
self.__preprocess_api_string(
247247
# Turn coordinates into a tile
@@ -445,7 +445,12 @@ def __zoom_range_check(self, layer: str, zoom: int):
445445
)
446446

447447
def __validation_checks(
448-
self, function, longitude: float, latitude: float, zoom: int, layer: str
448+
self,
449+
longitude: float,
450+
latitude: float,
451+
zoom: int,
452+
layer: str,
453+
layer_options: typing.List[str] = [],
449454
) -> None:
450455
"""
451456
Validation checks for the parameters of longitude, latitude, layer, zoom
@@ -465,7 +470,11 @@ def __validation_checks(
465470
:raises InvalidOptionError: Invalid option passed
466471
"""
467472
# Check if the correct literals were passed to the function
468-
LiteralEnforcementException.enforce_literal(function=function)
473+
LiteralEnforcementException.enforce_literal(
474+
option_selected=layer,
475+
options=self.__LAYER_TYPES if layer_options == [] else layer_options,
476+
param="layer",
477+
)
469478

470479
# Check the parameters for the correct range
471480
self.__check_parameters(longitude, latitude)

src/mapillary/models/exceptions.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
- License: MIT LICENSE
1414
"""
1515

16-
# Local imports
17-
import inspect
18-
19-
from typing import Literal, get_args, get_origin
20-
2116
# Package imports
2217
import typing
2318

@@ -349,19 +344,14 @@ def __init__(self, *args: object) -> None:
349344
super().__init__(*args)
350345

351346
@staticmethod
352-
def enforce_literal(function: any):
353-
frame = inspect.stack()[1].frame
354-
355-
*_, parameters = inspect.getargvalues(frame)
356-
357-
for name, literal in function.__annotations__.items():
358-
359-
if get_origin(literal) is Literal and name in parameters:
360-
361-
value = parameters[name]
347+
def enforce_literal(
348+
option_selected: str,
349+
options: typing.Union[typing.List[str], typing.List[int]],
350+
param: str,
351+
):
362352

363-
if value not in get_args(literal):
353+
if option_selected not in options:
364354

365-
raise InvalidOptionError(
366-
param=name, value=value, options=get_args(literal)
367-
)
355+
raise InvalidOptionError(
356+
param=param, value=option_selected, options=options
357+
)

0 commit comments

Comments
 (0)