Skip to content

Commit aa74da6

Browse files
ocefpafhansthen
andauthored
enforce py39 min (#2169)
* enforce py39 min * fix all lints * Fix mypy error messages (and removed unused typing info from function body) --------- Co-authored-by: Hans Then <[email protected]>
1 parent 4615898 commit aa74da6

File tree

11 files changed

+50
-54
lines changed

11 files changed

+50
-54
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
```python
44
# Your code here
5-
65
```
76
#### Problem description
87

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
environment-name: TEST
3535
init-shell: bash
3636
create-args: >-
37-
python=3.12
37+
python=3
3838
--file requirements.txt
3939
--file requirements-dev.txt
4040

.pre-commit-config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
files: requirements-dev.txt
1818

1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.11.12
20+
rev: v0.12.2
2121
hooks:
2222
- id: ruff
2323

@@ -28,7 +28,7 @@ repos:
2828
language_version: python3
2929

3030
- repo: https://github.com/keewis/blackdoc
31-
rev: v0.3.9
31+
rev: v0.4.1
3232
hooks:
3333
- id: blackdoc
3434

@@ -44,6 +44,11 @@ repos:
4444
.*\.json |
4545
)$
4646
47+
# - repo: https://github.com/woodruffw/zizmor-pre-commit
48+
# rev: v1.11.0
49+
# hooks:
50+
# - id: zizmor
51+
4752
ci:
4853
autofix_commit_msg: |
4954
[pre-commit.ci] auto fixes from pre-commit.com hooks

folium/elements.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from functools import wraps
2-
from typing import List, Tuple
32

43
from branca.element import (
54
CssLink,
@@ -24,8 +23,8 @@ def inner(self, *args, **kwargs):
2423
class JSCSSMixin(MacroElement):
2524
"""Render links to external Javascript and CSS resources."""
2625

27-
default_js: List[Tuple[str, str]] = []
28-
default_css: List[Tuple[str, str]] = []
26+
default_js: list[tuple[str, str]] = []
27+
default_css: list[tuple[str, str]] = []
2928

3029
# Since this is typically used as a mixin, we cannot
3130
# override the _template member variable here. It would
@@ -53,7 +52,7 @@ def add_js_link(self, name: str, url: str):
5352
"""Add or update JS resource link."""
5453
self._add_link(name, url, self.default_js)
5554

56-
def _add_link(self, name: str, url: str, default_list: List[Tuple[str, str]]):
55+
def _add_link(self, name: str, url: str, default_list: list[tuple[str, str]]):
5756
"""Modify a css or js link.
5857
5958
If `name` does not exist, the link will be appended

folium/features.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
import json
88
import operator
99
import warnings
10+
from collections.abc import Iterable, Sequence
1011
from typing import (
1112
Any,
1213
Callable,
13-
Dict,
14-
Iterable,
15-
List,
1614
Optional,
17-
Sequence,
18-
Tuple,
1915
Union,
2016
get_args,
2117
)
@@ -348,7 +344,7 @@ def render(self, **kwargs):
348344
name=self.get_name(),
349345
)
350346

351-
embed_mapping: Dict[Optional[int], Callable] = {
347+
embed_mapping = {
352348
1: self._embed_vegalite_v1,
353349
2: self._embed_vegalite_v2,
354350
3: self._embed_vegalite_v3,
@@ -851,7 +847,7 @@ def find_identifier(self) -> str:
851847
"field to your geojson data or set `embed=True`. "
852848
)
853849

854-
def _get_self_bounds(self) -> List[List[Optional[float]]]:
850+
def _get_self_bounds(self) -> list[list[Optional[float]]]:
855851
"""
856852
Computes the bounds of the object itself (not including it's children)
857853
in the form [[lat_min, lon_min], [lat_max, lon_max]].
@@ -871,7 +867,7 @@ def render(self, **kwargs):
871867
super().render()
872868

873869

874-
TypeStyleMapping = Dict[str, Union[str, List[Union[str, int]]]]
870+
TypeStyleMapping = dict[str, Union[str, list[Union[str, int]]]]
875871

876872

877873
class GeoJsonStyleMapper:
@@ -1756,9 +1752,9 @@ class DivIcon(MacroElement):
17561752
def __init__(
17571753
self,
17581754
html: Optional[str] = None,
1759-
icon_size: Optional[Tuple[int, int]] = None,
1760-
icon_anchor: Optional[Tuple[int, int]] = None,
1761-
popup_anchor: Optional[Tuple[int, int]] = None,
1755+
icon_size: Optional[tuple[int, int]] = None,
1756+
icon_anchor: Optional[tuple[int, int]] = None,
1757+
popup_anchor: Optional[tuple[int, int]] = None,
17621758
class_name: str = "empty",
17631759
):
17641760
super().__init__()
@@ -1932,12 +1928,12 @@ class CustomIcon(Icon):
19321928
def __init__(
19331929
self,
19341930
icon_image: Any,
1935-
icon_size: Optional[Tuple[int, int]] = None,
1936-
icon_anchor: Optional[Tuple[int, int]] = None,
1931+
icon_size: Optional[tuple[int, int]] = None,
1932+
icon_anchor: Optional[tuple[int, int]] = None,
19371933
shadow_image: Any = None,
1938-
shadow_size: Optional[Tuple[int, int]] = None,
1939-
shadow_anchor: Optional[Tuple[int, int]] = None,
1940-
popup_anchor: Optional[Tuple[int, int]] = None,
1934+
shadow_size: Optional[tuple[int, int]] = None,
1935+
shadow_anchor: Optional[tuple[int, int]] = None,
1936+
popup_anchor: Optional[tuple[int, int]] = None,
19411937
):
19421938
super(Icon, self).__init__()
19431939
self._name = "icon"
@@ -2016,7 +2012,7 @@ def __init__(
20162012
f"Unexpected type for argument `colormap`: {type(colormap)}"
20172013
)
20182014

2019-
out: Dict[str, List[List[List[float]]]] = {}
2015+
out: dict[str, list[list[list[float]]]] = {}
20202016
for (lat1, lng1), (lat2, lng2), color in zip(coords[:-1], coords[1:], colors):
20212017
out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
20222018
for key, val in out.items():

folium/folium.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import time
77
import webbrowser
8-
from typing import Any, List, Optional, Sequence, Union
8+
from collections.abc import Sequence
9+
from typing import Any, Optional, Union
910

1011
from branca.element import Element, Figure
1112

@@ -337,7 +338,7 @@ def __init__(
337338
**kwargs,
338339
)
339340

340-
self.objects_to_stay_in_front: List[Layer] = []
341+
self.objects_to_stay_in_front: list[Layer] = []
341342

342343
if isinstance(tiles, TileLayer):
343344
self.add_child(tiles)

folium/map.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import warnings
77
from collections import OrderedDict, defaultdict
8-
from typing import TYPE_CHECKING, DefaultDict, Optional, Sequence, Union, cast
8+
from collections.abc import Sequence
9+
from typing import TYPE_CHECKING, Optional, Union, cast
910

1011
from branca.element import Element, Figure, Html, MacroElement
1112

@@ -38,7 +39,7 @@ def __get__(self, obj, owner):
3839
class Class(MacroElement):
3940
"""The root class of the leaflet class hierarchy"""
4041

41-
_includes: DefaultDict[str, dict] = defaultdict(dict)
42+
_includes: defaultdict[str, dict] = defaultdict(dict)
4243

4344
@classmethod
4445
def include(cls, **kwargs):

folium/plugins/timeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, TextIO, Union
1+
from typing import Optional, TextIO, Union
22

33
from branca.element import MacroElement
44

@@ -242,7 +242,7 @@ def __init__(
242242
"""
243243
)
244244

245-
self.timelines: List[Timeline] = []
245+
self.timelines: list[Timeline] = []
246246
self.options = remove_empty(**kwargs)
247247

248248
def add_timelines(self, *args):

folium/utilities.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@
77
import re
88
import tempfile
99
import uuid
10+
from collections.abc import Iterable, Iterator, Sequence
1011
from contextlib import contextmanager
1112
from typing import (
1213
TYPE_CHECKING,
1314
Any,
1415
Callable,
15-
Dict,
16-
Iterable,
17-
Iterator,
18-
List,
1916
Literal,
2017
Optional,
21-
Sequence,
22-
Tuple,
23-
Type,
2418
Union,
2519
)
2620
from urllib.parse import urlparse, uses_netloc, uses_params, uses_relative
@@ -55,7 +49,7 @@
5549
TypePathOptions = Union[bool, str, float, None]
5650

5751
TypeBounds = Sequence[Sequence[float]]
58-
TypeBoundsReturn = List[List[Optional[float]]]
52+
TypeBoundsReturn = list[list[Optional[float]]]
5953

6054
TypeContainer = Union[Figure, Div, "Popup"]
6155
TypePosition = Literal["bottomright", "bottomleft", "topright", "topleft"]
@@ -66,7 +60,7 @@
6660
_VALID_URLS.add("data")
6761

6862

69-
def validate_location(location: Sequence[float]) -> List[float]:
63+
def validate_location(location: Sequence[float]) -> list[float]:
7064
"""Validate a single lat/lon coordinate pair and convert to a list
7165
7266
Validate that location:
@@ -126,7 +120,7 @@ def _validate_locations_basics(locations: TypeMultiLine) -> None:
126120
raise ValueError("Locations is empty.")
127121

128122

129-
def validate_locations(locations: TypeLine) -> List[List[float]]:
123+
def validate_locations(locations: TypeLine) -> list[list[float]]:
130124
"""Validate an iterable with lat/lon coordinate pairs."""
131125
locations = if_pandas_df_convert_to_numpy(locations)
132126
_validate_locations_basics(locations)
@@ -135,7 +129,7 @@ def validate_locations(locations: TypeLine) -> List[List[float]]:
135129

136130
def validate_multi_locations(
137131
locations: TypeMultiLine,
138-
) -> Union[List[List[float]], List[List[List[float]]]]:
132+
) -> Union[list[list[float]], list[list[list[float]]]]:
139133
"""Validate an iterable with possibly nested lists of coordinate pairs."""
140134
locations = if_pandas_df_convert_to_numpy(locations)
141135
_validate_locations_basics(locations)
@@ -215,7 +209,7 @@ def _is_url(url: str) -> bool:
215209

216210
def mercator_transform(
217211
data: Any,
218-
lat_bounds: Tuple[float, float],
212+
lat_bounds: tuple[float, float],
219213
origin: str = "upper",
220214
height_out: Optional[int] = None,
221215
) -> np.ndarray:
@@ -279,7 +273,7 @@ def mercator(x):
279273
return out
280274

281275

282-
def iter_coords(obj: Any) -> Iterator[Tuple[float, ...]]:
276+
def iter_coords(obj: Any) -> Iterator[tuple[float, ...]]:
283277
"""
284278
Returns all the coordinate tuples from a geometry or feature.
285279
@@ -313,13 +307,13 @@ def iter_coords(obj: Any) -> Iterator[Tuple[float, ...]]:
313307
def get_bounds(
314308
locations: Any,
315309
lonlat: bool = False,
316-
) -> List[List[Optional[float]]]:
310+
) -> list[list[Optional[float]]]:
317311
"""
318312
Computes the bounds of the object in the form
319313
[[lat_min, lon_min], [lat_max, lon_max]]
320314
321315
"""
322-
bounds: List[List[Optional[float]]] = [[None, None], [None, None]]
316+
bounds: list[list[Optional[float]]] = [[None, None], [None, None]]
323317
for point in iter_coords(locations):
324318
bounds = [
325319
[
@@ -397,22 +391,22 @@ def deep_copy(item_original: Element) -> Element:
397391
return item
398392

399393

400-
def get_obj_in_upper_tree(element: Element, cls: Type) -> Element:
394+
def get_obj_in_upper_tree(element: Element, cls: type) -> Element:
401395
"""Return the first object in the parent tree of class `cls`."""
402396
parent = element._parent
403397
if parent is None:
404398
raise ValueError(f"The top of the tree was reached without finding a {cls}")
405399
if not isinstance(parent, cls):
406400
return get_obj_in_upper_tree(parent, cls)
407-
return parent
401+
return parent # type: ignore
408402

409403

410-
def parse_options(**kwargs: TypeJsonValue) -> Dict[str, TypeJsonValueNoNone]:
404+
def parse_options(**kwargs: TypeJsonValue) -> dict[str, TypeJsonValueNoNone]:
411405
"""Return a dict with lower-camelcase keys and non-None values.."""
412406
return {camelize(key): value for key, value in kwargs.items() if value is not None}
413407

414408

415-
def remove_empty(**kwargs: TypeJsonValue) -> Dict[str, TypeJsonValueNoNone]:
409+
def remove_empty(**kwargs: TypeJsonValue) -> dict[str, TypeJsonValueNoNone]:
416410
"""Return a dict without None values."""
417411
return {key: value for key, value in kwargs.items() if value is not None}
418412

folium/vector_layers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
44
"""
55

6-
from typing import List, Optional, Sequence, Union
6+
from collections.abc import Sequence
7+
from typing import Optional, Union
78

89
from branca.element import MacroElement
910

@@ -147,7 +148,7 @@ def __init__(
147148
tooltip if isinstance(tooltip, Tooltip) else Tooltip(str(tooltip))
148149
)
149150

150-
def _get_self_bounds(self) -> List[List[Optional[float]]]:
151+
def _get_self_bounds(self) -> list[list[Optional[float]]]:
151152
"""Compute the bounds of the object itself."""
152153
return get_bounds(self.locations)
153154

@@ -289,7 +290,7 @@ def __init__(
289290
tooltip if isinstance(tooltip, Tooltip) else Tooltip(str(tooltip))
290291
)
291292

292-
def _get_self_bounds(self) -> List[List[Optional[float]]]:
293+
def _get_self_bounds(self) -> list[list[Optional[float]]]:
293294
"""Compute the bounds of the object itself."""
294295
return get_bounds(self.locations)
295296

0 commit comments

Comments
 (0)