Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
modify codegen instead of modifying autogenerated _template.py file
  • Loading branch information
emilykl committed Mar 13, 2025
commit b3aab37d257cd14e816a62ff80cb6a102708ae0a
25 changes: 20 additions & 5 deletions codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ 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 +375,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 +428,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