Skip to content

Commit ded1322

Browse files
authored
Merge pull request #5086 from plotly/fix-deprecationwarning-fix
Fix bogus `DeprecationWarning`s in codegen rather than in autogenerated file
2 parents 0968434 + 22aa9ba commit ded1322

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

codegen/datatypes.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ 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 (
106+
node.name_property in deprecated_mapbox_traces
107+
or node.name_property == "template"
108+
):
109+
buffer.write(f"import warnings\n")
107110

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

382400
# ### Literals ###
383401
if literal_nodes:
@@ -413,7 +431,7 @@ def __init__(self"""
413431
if node.name_property in deprecated_mapbox_traces:
414432
buffer.write(
415433
f"""
416-
warn(
434+
warnings.warn(
417435
"*{node.name_property}* is deprecated!"
418436
+ " Use *{node.name_property.replace("mapbox", "map")}* instead."
419437
+ " Learn more at: https://plotly.com/python/mapbox-to-maplibre/",

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/",

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/",

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/",

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)