Skip to content

Commit b3aab37

Browse files
committed
modify codegen instead of modifying autogenerated _template.py file
1 parent 0968434 commit b3aab37

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

Diff for: codegen/datatypes.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def build_datatype_py(node):
102102
)
103103
buffer.write(f"import copy as _copy\n")
104104

105-
if node.name_property in deprecated_mapbox_traces:
106-
buffer.write(f"from warnings import warn\n")
105+
if node.name_property in deprecated_mapbox_traces or node.name_property == "template":
106+
buffer.write(f"import warnings\n")
107107

108108
# Write class definition
109109
# ----------------------
@@ -375,9 +375,24 @@ def __init__(self"""
375375
f"""
376376
_v = arg.pop('{name_prop}', None)
377377
_v = {name_prop} if {name_prop} is not None else _v
378-
if _v is not None:
379-
self['{name_prop}'] = _v"""
378+
if _v is not None:"""
380379
)
380+
if datatype_class == "Template" and name_prop == "data":
381+
buffer.write(
382+
"""
383+
# Template.data contains a 'scattermapbox' key, which causes a
384+
# go.Scattermapbox trace object to be created during validation.
385+
# In order to prevent false deprecation warnings from surfacing,
386+
# we suppress deprecation warnings for this line only.
387+
with warnings.catch_warnings():
388+
warnings.filterwarnings("ignore", category=DeprecationWarning)
389+
self["data"] = _v"""
390+
)
391+
else:
392+
buffer.write(
393+
f"""
394+
self['{name_prop}'] = _v"""
395+
)
381396

382397
# ### Literals ###
383398
if literal_nodes:
@@ -413,7 +428,7 @@ def __init__(self"""
413428
if node.name_property in deprecated_mapbox_traces:
414429
buffer.write(
415430
f"""
416-
warn(
431+
warnings.warn(
417432
"*{node.name_property}* is deprecated!"
418433
+ " Use *{node.name_property.replace("mapbox", "map")}* instead."
419434
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",

Diff for: plotly/graph_objs/_choroplethmapbox.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
22
import copy as _copy
3-
from warnings import warn
3+
import warnings
44

55

66
class Choroplethmapbox(_BaseTraceType):
@@ -2380,7 +2380,7 @@ def __init__(
23802380
# ------------------
23812381
self._skip_invalid = False
23822382

2383-
warn(
2383+
warnings.warn(
23842384
"*choroplethmapbox* is deprecated!"
23852385
+ " Use *choroplethmap* instead."
23862386
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",

Diff for: plotly/graph_objs/_densitymapbox.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
22
import copy as _copy
3-
from warnings import warn
3+
import warnings
44

55

66
class Densitymapbox(_BaseTraceType):
@@ -2321,7 +2321,7 @@ def __init__(
23212321
# ------------------
23222322
self._skip_invalid = False
23232323

2324-
warn(
2324+
warnings.warn(
23252325
"*densitymapbox* is deprecated!"
23262326
+ " Use *densitymap* instead."
23272327
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",

Diff for: plotly/graph_objs/_scattermapbox.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
22
import copy as _copy
3-
from warnings import warn
3+
import warnings
44

55

66
class Scattermapbox(_BaseTraceType):
@@ -2294,7 +2294,7 @@ def __init__(
22942294
# ------------------
22952295
self._skip_invalid = False
22962296

2297-
warn(
2297+
warnings.warn(
22982298
"*scattermapbox* is deprecated!"
22992299
+ " Use *scattermap* instead."
23002300
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",

Diff for: plotly/graph_objs/layout/_template.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType
12
import copy as _copy
23
import warnings
34

4-
from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType
5-
65

76
class Template(_BaseLayoutHierarchyType):
7+
88
# class properties
99
# --------------------
1010
_parent_path_str = "layout"

0 commit comments

Comments
 (0)