8
8
9
9
import plotly
10
10
from plotly .io ._utils import validate_coerce_fig_to_dict , broadcast_args_to_dicts
11
- from plotly .io import defaults
11
+ from plotly .io . _defaults import defaults
12
12
13
13
ENGINE_SUPPORT_TIMELINE = "September 2025"
14
14
@@ -98,19 +98,30 @@ def __setattr__(self, name, value):
98
98
DeprecationWarning ,
99
99
stacklevel = 2 ,
100
100
)
101
- setattr (defaults , name , value )
102
- super (PlotlyScopeWithDeprecationWarnings , self ).__setattr__ (name , value )
101
+ super ().__setattr__ (name , value )
103
102
104
103
def __getattr__ (self , name ):
105
- if name in defaults . __dict__ :
104
+ if hasattr ( defaults , name ) :
106
105
warnings .warn (
107
106
kaleido_scope_default_warning_func (name ),
108
107
DeprecationWarning ,
109
108
stacklevel = 2 ,
110
109
)
111
- return super (PlotlyScopeWithDeprecationWarnings , self ).__getattr__ (name )
110
+ return super ().__getattr__ (name )
111
+
112
+ # Ensure the new method of setting defaults is backwards compatible with Kaleido v0
113
+ class DefaultsBackwardsCompatible (defaults .__class__ ):
114
+ def __init__ (self , scope ):
115
+ self ._scope = scope
116
+ super ().__init__ ()
117
+ def __setattr__ (self , name , value ):
118
+ if not name == "_scope" :
119
+ if hasattr (self ._scope , name ) and getattr (self ._scope , name ) != value :
120
+ setattr (self ._scope , name , value )
121
+ super ().__setattr__ (name , value )
112
122
113
123
scope = PlotlyScopeWithDeprecationWarnings ()
124
+ defaults = DefaultsBackwardsCompatible (scope )
114
125
# Compute absolute path to the 'plotly/package_data/' directory
115
126
root_dir = os .path .dirname (os .path .abspath (plotly .__file__ ))
116
127
package_dir = os .path .join (root_dir , "package_data" )
@@ -126,7 +137,7 @@ def __getattr__(self, name):
126
137
# Show a deprecation warning if the old method of setting defaults is used
127
138
class DefaultsDeprecationWarning :
128
139
def __getattr__ (self , name ):
129
- if name in defaults . __dict__ :
140
+ if hasattr ( defaults , name ) :
130
141
warnings .warn (
131
142
kaleido_scope_default_warning_func (name ),
132
143
DeprecationWarning ,
@@ -137,7 +148,7 @@ def __getattr__(self, name):
137
148
raise AttributeError (bad_attribute_error_msg_func (name ))
138
149
139
150
def __setattr__ (self , name , value ):
140
- if name in defaults . __dict__ :
151
+ if hasattr ( defaults , name ) :
141
152
warnings .warn (
142
153
kaleido_scope_default_warning_func (name ),
143
154
DeprecationWarning ,
@@ -344,9 +355,7 @@ def to_image(
344
355
height = height or defaults .default_height ,
345
356
scale = scale or defaults .default_scale ,
346
357
),
347
- topojson = Path (defaults .topojson ).as_uri ()
348
- if defaults .topojson
349
- else None ,
358
+ topojson = defaults .topojson ,
350
359
# mathjax=Path(defaults.mathjax).as_uri() if defaults.mathjax else None,
351
360
)
352
361
except choreographer .errors .ChromeNotFoundError :
@@ -615,7 +624,7 @@ def write_images(
615
624
height = d ["height" ] or defaults .default_height ,
616
625
scale = d ["scale" ] or defaults .default_scale ,
617
626
),
618
- "topojson" : Path ( defaults .topojson ). as_uri () if defaults . topojson else None ,
627
+ "topojson" : defaults .topojson ,
619
628
# "mathjax": Path(defaults.mathjax).as_uri() if defaults.mathjax else None,
620
629
}
621
630
for d in arg_dicts
0 commit comments