Skip to content

Fix bogus DeprecationWarnings in codegen rather than in autogenerated file #5086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ----------------------
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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/",
Expand Down
4 changes: 2 additions & 2 deletions plotly/graph_objs/_choroplethmapbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
import copy as _copy
from warnings import warn
import warnings


class Choroplethmapbox(_BaseTraceType):
Expand Down Expand Up @@ -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/",
Expand Down
4 changes: 2 additions & 2 deletions plotly/graph_objs/_densitymapbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
import copy as _copy
from warnings import warn
import warnings


class Densitymapbox(_BaseTraceType):
Expand Down Expand Up @@ -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/",
Expand Down
4 changes: 2 additions & 2 deletions plotly/graph_objs/_scattermapbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from plotly.basedatatypes import BaseTraceType as _BaseTraceType
import copy as _copy
from warnings import warn
import warnings


class Scattermapbox(_BaseTraceType):
Expand Down Expand Up @@ -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/",
Expand Down
4 changes: 2 additions & 2 deletions plotly/graph_objs/layout/_template.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down