diff --git a/codegen/datatypes.py b/codegen/datatypes.py index deb1c9bbdf..178c777850 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -102,8 +102,11 @@ def build_datatype_py(node): ) buffer.write(f"import copy as _copy\n") - if node.name_property in deprecated_mapbox_traces: - buffer.write(f"from warnings import warn\n") + if ( + node.name_property in deprecated_mapbox_traces + or node.name_property == "template" + ): + buffer.write(f"import warnings\n") # Write class definition # ---------------------- @@ -375,9 +378,24 @@ def __init__(self""" f""" _v = arg.pop('{name_prop}', None) _v = {name_prop} if {name_prop} is not None else _v - if _v is not None: - self['{name_prop}'] = _v""" + if _v is not None:""" ) + if datatype_class == "Template" and name_prop == "data": + buffer.write( + """ + # Template.data contains a 'scattermapbox' key, which causes a + # go.Scattermapbox trace object to be created during validation. + # In order to prevent false deprecation warnings from surfacing, + # we suppress deprecation warnings for this line only. + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + self["data"] = _v""" + ) + else: + buffer.write( + f""" + self['{name_prop}'] = _v""" + ) # ### Literals ### if literal_nodes: @@ -413,7 +431,7 @@ def __init__(self""" if node.name_property in deprecated_mapbox_traces: buffer.write( f""" - warn( + warnings.warn( "*{node.name_property}* is deprecated!" + " Use *{node.name_property.replace("mapbox", "map")}* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/_choroplethmapbox.py b/plotly/graph_objs/_choroplethmapbox.py index c1c14e6d4a..9169bfcc15 100644 --- a/plotly/graph_objs/_choroplethmapbox.py +++ b/plotly/graph_objs/_choroplethmapbox.py @@ -1,6 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy -from warnings import warn +import warnings class Choroplethmapbox(_BaseTraceType): @@ -2380,7 +2380,7 @@ def __init__( # ------------------ self._skip_invalid = False - warn( + warnings.warn( "*choroplethmapbox* is deprecated!" + " Use *choroplethmap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/_densitymapbox.py b/plotly/graph_objs/_densitymapbox.py index 8498ab2d17..3623258306 100644 --- a/plotly/graph_objs/_densitymapbox.py +++ b/plotly/graph_objs/_densitymapbox.py @@ -1,6 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy -from warnings import warn +import warnings class Densitymapbox(_BaseTraceType): @@ -2321,7 +2321,7 @@ def __init__( # ------------------ self._skip_invalid = False - warn( + warnings.warn( "*densitymapbox* is deprecated!" + " Use *densitymap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/_scattermapbox.py b/plotly/graph_objs/_scattermapbox.py index c7494d48fb..9f98a2b1af 100644 --- a/plotly/graph_objs/_scattermapbox.py +++ b/plotly/graph_objs/_scattermapbox.py @@ -1,6 +1,6 @@ from plotly.basedatatypes import BaseTraceType as _BaseTraceType import copy as _copy -from warnings import warn +import warnings class Scattermapbox(_BaseTraceType): @@ -2294,7 +2294,7 @@ def __init__( # ------------------ self._skip_invalid = False - warn( + warnings.warn( "*scattermapbox* is deprecated!" + " Use *scattermap* instead." + " Learn more at: https://plotly.com/python/mapbox-to-maplibre/", diff --git a/plotly/graph_objs/layout/_template.py b/plotly/graph_objs/layout/_template.py index 69f6cf38ec..1f90ba94cb 100644 --- a/plotly/graph_objs/layout/_template.py +++ b/plotly/graph_objs/layout/_template.py @@ -1,10 +1,10 @@ +from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType import copy as _copy import warnings -from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType - class Template(_BaseLayoutHierarchyType): + # class properties # -------------------- _parent_path_str = "layout"