Skip to content

Commit 3ccc598

Browse files
committed
Update generate_graph_objects_docs.py
1 parent 7637ad2 commit 3ccc598

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

scripts/generate_graph_objects_docs.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,26 @@ def is_class(self, obj) -> bool:
3939
"""Check if an object is a class."""
4040
return inspect.isclass(obj) and not obj.__name__.startswith('_')
4141

42-
def is_deprecated_class(self, class_name: str) -> bool:
43-
"""Check if a class is deprecated and should be handled specially."""
44-
# Only mark classes as deprecated if they are actually deprecated at the top level
45-
# These classes show deprecation warnings when instantiated
46-
deprecated_classes = {
47-
'AngularAxis', 'Annotation', 'Annotations', 'Choroplethmapbox', 'ColorBar',
48-
'Contours', 'Data', 'Densitymapbox', 'ErrorX', 'ErrorY', 'ErrorZ', 'Font',
49-
'Frames', 'Histogram2dcontour', 'Legend', 'Line', 'Margin', 'Marker',
50-
'RadialAxis', 'Scattermapbox', 'Scene', 'Stream', 'Trace', 'XAxis', 'XBins',
51-
'YAxis', 'YBins', 'ZAxis'
52-
}
53-
return class_name in deprecated_classes
42+
def is_deprecated_class(self, full_class_name: str, class_obj: Any) -> bool:
43+
"""Check if a class is deprecated by testing for deprecation warnings."""
44+
import warnings
45+
46+
try:
47+
# Capture warnings when instantiating the class
48+
with warnings.catch_warnings(record=True) as w:
49+
warnings.simplefilter("always")
50+
# Try to instantiate the class (this triggers deprecation warnings)
51+
class_obj()
52+
53+
# Check if any warnings contain "deprecat"
54+
for warning in w:
55+
if 'deprecat' in str(warning.message).lower():
56+
return True
57+
return False
58+
except Exception:
59+
# If we can't instantiate it, assume it's not deprecated
60+
# (it might just require parameters or have other issues)
61+
return False
5462

5563
def is_package(self, obj) -> bool:
5664
"""Check if an object is a package/module."""
@@ -167,8 +175,7 @@ def generate_class_page(self, class_name: str, class_obj: Any) -> Path:
167175
content = f"# {class_name}\n\n"
168176

169177
# Check if this is a deprecated class
170-
class_short_name = parts[-1]
171-
if self.inspector.is_deprecated_class(class_short_name):
178+
if self.inspector.is_deprecated_class(class_name, class_obj):
172179
content += f"**⚠️ DEPRECATED**: This class is deprecated and may not be available for import.\n\n"
173180
content += f"Please refer to the specific implementation in the appropriate submodule.\n\n"
174181
# Don't use ::: syntax for deprecated classes as they can't be imported
@@ -295,8 +302,9 @@ def generate_main_index(self) -> Path:
295302
if top_level_classes:
296303
content += "## Classes\n\n"
297304
for short_name, full_name in top_level_classes:
298-
# Check if deprecated
299-
if self.inspector.is_deprecated_class(short_name):
305+
# Check if deprecated - get the class object
306+
class_obj = self.inspector.classes[full_name]
307+
if self.inspector.is_deprecated_class(full_name, class_obj):
300308
content += f"- [{short_name}]({short_name}.md) ⚠️ *Deprecated*\n"
301309
else:
302310
content += f"- [{short_name}]({short_name}.md)\n"
@@ -309,9 +317,14 @@ def generate_main_index(self) -> Path:
309317
content += f"- [{short_name}]({package_folder_name}/index.md)\n"
310318
content += "\n"
311319

312-
if self.inspector.is_deprecated_class("AngularAxis"): # Check if any deprecated classes exist
313-
content += "## Notes\n\n"
314-
content += "⚠️ **Deprecated Classes**: Some classes marked as deprecated are legacy classes that have been replaced with more specific implementations in submodules. Please refer to the specific implementation in the appropriate submodule for current usage.\n"
320+
# Check if any deprecated classes exist by testing a known deprecated class
321+
try:
322+
angular_axis_obj = self.inspector.classes.get("plotly.graph_objs.AngularAxis")
323+
if angular_axis_obj and self.inspector.is_deprecated_class("plotly.graph_objs.AngularAxis", angular_axis_obj):
324+
content += "## Notes\n\n"
325+
content += "⚠️ **Deprecated Classes**: Some classes marked as deprecated are legacy classes that have been replaced with more specific implementations in submodules. Please refer to the specific implementation in the appropriate submodule for current usage.\n"
326+
except Exception:
327+
pass # Skip notes section if we can't check deprecation
315328

316329
# Write the file
317330
file_path.write_text(content)

0 commit comments

Comments
 (0)