diff --git a/plotly/graph_objs/_figure.py b/plotly/graph_objs/_figure.py index 99529b66f1..847a3bc62a 100644 --- a/plotly/graph_objs/_figure.py +++ b/plotly/graph_objs/_figure.py @@ -21976,6 +21976,15 @@ def select_mapboxes(self, selector=None, row=None, col=None): objects that satisfy all of the specified selection criteria """ + # Optimize by avoiding Python's generic machinery for this common case + # of "select all mapbox objects" with no selector and no row/col filtering. + if selector is None and row is None and col is None: + layout = self.layout + mapbox_keys = [ + k for k in layout if k.startswith("mapbox") and layout[k] is not None + ] + # Prefer generator expression for memory efficiency (instead of list -> generator) + return (layout[k] for k in mapbox_keys) return self._select_layout_subplots_by_prefix("mapbox", selector, row, col) def for_each_mapbox(self, fn, selector=None, row=None, col=None) -> "Figure": @@ -22009,7 +22018,6 @@ def for_each_mapbox(self, fn, selector=None, row=None, col=None) -> "Figure": """ for obj in self.select_mapboxes(selector=selector, row=row, col=col): fn(obj) - return self def update_mapboxes(