Skip to content

Commit 088624f

Browse files
committed
fix new ruff (pyupgrade) errors using ruff check --fix (mostly)
1 parent 0f2d9e8 commit 088624f

14 files changed

Lines changed: 153 additions & 172 deletions

‎docs/conf.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
# General information about the project.
5050
import datetime
5151

52-
year = datetime.datetime.now(tz=datetime.timezone.utc).date().year
52+
year = datetime.datetime.now(tz=datetime.UTC).date().year
5353
project = "Folium"
5454
copyright = f"2013-{year}, Rob Story"
5555

‎folium/features.py‎

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import json
88
import operator
99
import warnings
10-
from collections.abc import Iterable, Sequence
10+
from collections.abc import Callable, Iterable, Sequence
1111
from typing import (
1212
Any,
13-
Callable,
1413
Optional,
1514
Union,
1615
get_args,
@@ -103,8 +102,8 @@ def __init__(
103102
number_of_sides: int = 4,
104103
rotation: int = 0,
105104
radius: int = 15,
106-
popup: Union[Popup, str, None] = None,
107-
tooltip: Union[Tooltip, str, None] = None,
105+
popup: Popup | str | None = None,
106+
tooltip: Tooltip | str | None = None,
108107
**kwargs: TypePathOptions,
109108
):
110109
super().__init__(location, popup=popup, tooltip=tooltip)
@@ -159,10 +158,10 @@ class Vega(JSCSSMixin):
159158
def __init__(
160159
self,
161160
data: Any,
162-
width: Union[int, str, None] = None,
163-
height: Union[int, str, None] = None,
164-
left: Union[int, str] = "0%",
165-
top: Union[int, str] = "0%",
161+
width: int | str | None = None,
162+
height: int | str | None = None,
163+
left: int | str = "0%",
164+
top: int | str = "0%",
166165
position: str = "relative",
167166
):
168167
super().__init__()
@@ -264,10 +263,10 @@ class VegaLite(MacroElement):
264263
def __init__(
265264
self,
266265
data: Any,
267-
width: Union[int, str, None] = None,
268-
height: Union[int, str, None] = None,
269-
left: Union[int, str] = "0%",
270-
top: Union[int, str] = "0%",
266+
width: int | str | None = None,
267+
height: int | str | None = None,
268+
left: int | str = "0%",
269+
top: int | str = "0%",
271270
position: str = "relative",
272271
):
273272
super(self.__class__, self).__init__()
@@ -338,7 +337,7 @@ def render(self, **kwargs):
338337
embed_vegalite(figure=figure, parent=parent)
339338

340339
@property
341-
def vegalite_major_version(self) -> Optional[int]:
340+
def vegalite_major_version(self) -> int | None:
342341
if "$schema" not in self.data:
343342
return None
344343

@@ -678,26 +677,26 @@ class GeoJson(Layer):
678677
def __init__(
679678
self,
680679
data: Any,
681-
style_function: Optional[Callable] = None,
682-
highlight_function: Optional[Callable] = None,
680+
style_function: Callable | None = None,
681+
highlight_function: Callable | None = None,
683682
popup_keep_highlighted: bool = False,
684-
name: Optional[str] = None,
683+
name: str | None = None,
685684
overlay: bool = True,
686685
control: bool = True,
687686
show: bool = True,
688-
smooth_factor: Optional[float] = None,
687+
smooth_factor: float | None = None,
689688
tooltip: Union[str, Tooltip, "GeoJsonTooltip", None] = None,
690689
embed: bool = True,
691690
popup: Optional["GeoJsonPopup"] = None,
692691
zoom_on_click: bool = False,
693-
on_each_feature: Optional[JsCode] = None,
694-
marker: Union[Circle, CircleMarker, Marker, None] = None,
692+
on_each_feature: JsCode | None = None,
693+
marker: Circle | CircleMarker | Marker | None = None,
695694
**kwargs: Any,
696695
):
697696
super().__init__(name=name, overlay=overlay, control=control, show=show)
698697
self._name = "GeoJson"
699698
self.embed = embed
700-
self.embed_link: Optional[str] = None
699+
self.embed_link: str | None = None
701700
self.json = None
702701
self.parent_map = None
703702
self.smooth_factor = smooth_factor
@@ -845,7 +844,7 @@ def find_identifier(self) -> str:
845844
"field to your geojson data or set `embed=True`. "
846845
)
847846

848-
def _get_self_bounds(self) -> list[list[Optional[float]]]:
847+
def _get_self_bounds(self) -> list[list[float | None]]:
849848
"""
850849
Computes the bounds of the object itself (not including it's children)
851850
in the form [[lat_min, lon_min], [lat_max, lon_max]].
@@ -865,7 +864,7 @@ def render(self, **kwargs):
865864
super().render()
866865

867866

868-
TypeStyleMapping = dict[str, Union[str, list[Union[str, int]]]]
867+
TypeStyleMapping = dict[str, str | list[str | int]]
869868

870869

871870
class GeoJsonStyleMapper:
@@ -912,7 +911,7 @@ def _create_mapping(self, func: Callable, switch: str) -> TypeStyleMapping:
912911
self._set_default_key(mapping)
913912
return mapping
914913

915-
def get_feature_id(self, feature: dict) -> Union[str, int]:
914+
def get_feature_id(self, feature: dict) -> str | int:
916915
"""Return a value identifying the feature."""
917916
prefix = "feature.properties["
918917
if self.feature_identifier.startswith(prefix):
@@ -1025,13 +1024,13 @@ def __init__(
10251024
self,
10261025
data: Any,
10271026
object_path: str,
1028-
style_function: Optional[Callable] = None,
1029-
name: Optional[str] = None,
1027+
style_function: Callable | None = None,
1028+
name: str | None = None,
10301029
overlay: bool = True,
10311030
control: bool = True,
10321031
show: bool = True,
1033-
smooth_factor: Optional[float] = None,
1034-
tooltip: Union[str, Tooltip, None] = None,
1032+
smooth_factor: float | None = None,
1033+
tooltip: str | Tooltip | None = None,
10351034
):
10361035
super().__init__(name=name, overlay=overlay, control=control, show=show)
10371036
self._name = "TopoJson"
@@ -1161,10 +1160,10 @@ class GeoJsonDetail(MacroElement):
11611160
def __init__(
11621161
self,
11631162
fields: Sequence[str],
1164-
aliases: Optional[Sequence[str]] = None,
1163+
aliases: Sequence[str] | None = None,
11651164
labels: bool = True,
11661165
localize: bool = False,
1167-
style: Optional[str] = None,
1166+
style: str | None = None,
11681167
class_name: str = "geojsondetail",
11691168
):
11701169
super().__init__()
@@ -1311,10 +1310,10 @@ class GeoJsonTooltip(GeoJsonDetail):
13111310
def __init__(
13121311
self,
13131312
fields: Sequence[str],
1314-
aliases: Optional[Sequence[str]] = None,
1313+
aliases: Sequence[str] | None = None,
13151314
labels: bool = True,
13161315
localize: bool = False,
1317-
style: Optional[str] = None,
1316+
style: str | None = None,
13181317
class_name: str = "foliumtooltip",
13191318
sticky: bool = True,
13201319
**kwargs: TypeJsonValue,
@@ -1379,7 +1378,7 @@ class GeoJsonPopup(GeoJsonDetail):
13791378
def __init__(
13801379
self,
13811380
fields: Sequence[str],
1382-
aliases: Optional[Sequence[str]] = None,
1381+
aliases: Sequence[str] | None = None,
13831382
labels: bool = True,
13841383
style: str = "margin: auto;",
13851384
class_name: str = "foliumpopup",
@@ -1520,24 +1519,24 @@ class Choropleth(FeatureGroup):
15201519
def __init__(
15211520
self,
15221521
geo_data: Any,
1523-
data: Optional[Any] = None,
1524-
columns: Optional[Sequence[Any]] = None,
1525-
key_on: Optional[str] = None,
1526-
bins: Union[int, Sequence[float]] = 6,
1527-
fill_color: Optional[str] = None,
1522+
data: Any | None = None,
1523+
columns: Sequence[Any] | None = None,
1524+
key_on: str | None = None,
1525+
bins: int | Sequence[float] = 6,
1526+
fill_color: str | None = None,
15281527
nan_fill_color: str = "black",
15291528
fill_opacity: float = 0.6,
1530-
nan_fill_opacity: Optional[float] = None,
1529+
nan_fill_opacity: float | None = None,
15311530
line_color: str = "black",
15321531
line_weight: float = 1,
15331532
line_opacity: float = 1,
1534-
name: Optional[str] = None,
1533+
name: str | None = None,
15351534
legend_name: str = "",
15361535
overlay: bool = True,
15371536
control: bool = True,
15381537
show: bool = True,
1539-
topojson: Optional[str] = None,
1540-
smooth_factor: Optional[float] = None,
1538+
topojson: str | None = None,
1539+
smooth_factor: float | None = None,
15411540
highlight: bool = False,
15421541
use_jenks: bool = False,
15431542
**kwargs,
@@ -1668,7 +1667,7 @@ def highlight_function(x):
16681667
return {"weight": line_weight + 2, "fillOpacity": fill_opacity + 0.2}
16691668

16701669
if topojson:
1671-
self.geojson: Union[TopoJson, GeoJson] = TopoJson(
1670+
self.geojson: TopoJson | GeoJson = TopoJson(
16721671
geo_data,
16731672
topojson,
16741673
style_function=style_function,
@@ -1687,7 +1686,7 @@ def highlight_function(x):
16871686
self.add_child(self.color_scale)
16881687

16891688
@classmethod
1690-
def _get_by_key(cls, obj: Union[dict, list], key: str) -> Union[float, str, None]:
1689+
def _get_by_key(cls, obj: dict | list, key: str) -> float | str | None:
16911690
key_parts = key.split(".")
16921691
first_key_part = key_parts[0]
16931692
if first_key_part.isdigit():
@@ -1748,10 +1747,10 @@ class DivIcon(MacroElement):
17481747

17491748
def __init__(
17501749
self,
1751-
html: Optional[str] = None,
1752-
icon_size: Optional[tuple[int, int]] = None,
1753-
icon_anchor: Optional[tuple[int, int]] = None,
1754-
popup_anchor: Optional[tuple[int, int]] = None,
1750+
html: str | None = None,
1751+
icon_size: tuple[int, int] | None = None,
1752+
icon_anchor: tuple[int, int] | None = None,
1753+
popup_anchor: tuple[int, int] | None = None,
17551754
class_name: str = "empty",
17561755
):
17571756
super().__init__()
@@ -1825,7 +1824,7 @@ class ClickForMarker(MacroElement):
18251824
{% endmacro %}
18261825
""") # noqa
18271826

1828-
def __init__(self, popup: Union[IFrame, Html, str, None] = None):
1827+
def __init__(self, popup: IFrame | Html | str | None = None):
18291828
super().__init__()
18301829
self._name = "ClickForMarker"
18311830

@@ -1866,7 +1865,7 @@ class ClickForLatLng(MacroElement):
18661865
{% endmacro %}
18671866
""") # noqa
18681867

1869-
def __init__(self, format_str: Optional[str] = None, alert: bool = True):
1868+
def __init__(self, format_str: str | None = None, alert: bool = True):
18701869
super().__init__()
18711870
self._name = "ClickForLatLng"
18721871
self.format_str = format_str or 'lat + "," + lng'
@@ -1917,12 +1916,12 @@ class CustomIcon(Icon):
19171916
def __init__(
19181917
self,
19191918
icon_image: Any,
1920-
icon_size: Optional[tuple[int, int]] = None,
1921-
icon_anchor: Optional[tuple[int, int]] = None,
1919+
icon_size: tuple[int, int] | None = None,
1920+
icon_anchor: tuple[int, int] | None = None,
19221921
shadow_image: Any = None,
1923-
shadow_size: Optional[tuple[int, int]] = None,
1924-
shadow_anchor: Optional[tuple[int, int]] = None,
1925-
popup_anchor: Optional[tuple[int, int]] = None,
1922+
shadow_size: tuple[int, int] | None = None,
1923+
shadow_anchor: tuple[int, int] | None = None,
1924+
popup_anchor: tuple[int, int] | None = None,
19261925
):
19271926
super(Icon, self).__init__()
19281927
self._name = "icon"
@@ -1970,10 +1969,10 @@ def __init__(
19701969
self,
19711970
positions: TypeLine,
19721971
colors: Iterable[float],
1973-
colormap: Union[ColorMap, Sequence[Any], None] = None,
1972+
colormap: ColorMap | Sequence[Any] | None = None,
19741973
nb_steps: int = 12,
1975-
weight: Optional[int] = None,
1976-
opacity: Optional[float] = None,
1974+
weight: int | None = None,
1975+
opacity: float | None = None,
19771976
**kwargs: Any,
19781977
):
19791978
super().__init__(**kwargs)
@@ -2045,9 +2044,9 @@ class Control(JSCSSMixin, Class):
20452044

20462045
def __init__(
20472046
self,
2048-
control: Optional[str] = None,
2047+
control: str | None = None,
20492048
*args,
2050-
position: Optional[TypePosition] = None,
2049+
position: TypePosition | None = None,
20512050
**kwargs,
20522051
):
20532052
super().__init__()

‎folium/folium.py‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import webbrowser
88
from collections.abc import Sequence
99
from importlib.resources import files as _resource_files
10-
from typing import Any, Optional, Union
10+
from typing import Any
1111

1212
from branca.element import Element, Figure
1313

@@ -273,16 +273,16 @@ class Map(JSCSSMixin, Evented):
273273

274274
def __init__(
275275
self,
276-
location: Optional[Sequence[float]] = None,
277-
width: Union[str, float] = "100%",
278-
height: Union[str, float] = "100%",
279-
left: Union[str, float] = "0%",
280-
top: Union[str, float] = "0%",
276+
location: Sequence[float] | None = None,
277+
width: str | float = "100%",
278+
height: str | float = "100%",
279+
left: str | float = "0%",
280+
top: str | float = "0%",
281281
position: str = "relative",
282-
tiles: Union[str, TileLayer, None] = "OpenStreetMap",
283-
attr: Optional[str] = None,
284-
min_zoom: Optional[int] = None,
285-
max_zoom: Optional[int] = None,
282+
tiles: str | TileLayer | None = "OpenStreetMap",
283+
attr: str | None = None,
284+
min_zoom: int | None = None,
285+
max_zoom: int | None = None,
286286
zoom_start: int = 10,
287287
min_lat: float = -90,
288288
max_lat: float = 90,
@@ -295,14 +295,14 @@ def __init__(
295295
no_touch: bool = False,
296296
disable_3d: bool = False,
297297
png_enabled: bool = False,
298-
zoom_control: Union[bool, str] = True,
298+
zoom_control: bool | str = True,
299299
font_size: str = "1rem",
300300
**kwargs: TypeJsonValue,
301301
):
302302
super().__init__()
303303
self._name = "Map"
304304

305-
self._png_image: Optional[bytes] = None
305+
self._png_image: bytes | None = None
306306
self.png_enabled = png_enabled
307307

308308
if location is None:
@@ -374,7 +374,7 @@ def _repr_html_(self, **kwargs) -> str:
374374
return out
375375

376376
def _to_png(
377-
self, delay: int = 3, driver: Any = None, size: Optional[Sequence[int]] = None
377+
self, delay: int = 3, driver: Any = None, size: Sequence[int] | None = None
378378
) -> bytes:
379379
"""Export the HTML to byte representation of a PNG image.
380380
@@ -426,7 +426,7 @@ def _to_png(
426426
self._png_image = png
427427
return self._png_image
428428

429-
def _repr_png_(self) -> Optional[bytes]:
429+
def _repr_png_(self) -> bytes | None:
430430
"""Displays the PNG Map in a Jupyter notebook."""
431431
# The notebook calls all _repr_*_ by default.
432432
# We don't want that here b/c this one is quite slow.
@@ -452,10 +452,10 @@ def show_in_browser(self) -> None:
452452
def fit_bounds(
453453
self,
454454
bounds: TypeBounds,
455-
padding_top_left: Optional[Sequence[float]] = None,
456-
padding_bottom_right: Optional[Sequence[float]] = None,
457-
padding: Optional[Sequence[float]] = None,
458-
max_zoom: Optional[int] = None,
455+
padding_top_left: Sequence[float] | None = None,
456+
padding_bottom_right: Sequence[float] | None = None,
457+
padding: Sequence[float] | None = None,
458+
max_zoom: int | None = None,
459459
) -> None:
460460
"""Fit the map to contain a bounding box with the
461461
maximum zoom level possible.

0 commit comments

Comments
 (0)