Skip to content

Commit ef0fa03

Browse files
authored
FIX free-threaded failure because dictionary changed size during iteration (#32264)
1 parent e891db8 commit ef0fa03

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sklearn/utils/_metadata_requests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,12 @@ def _get_class_level_metadata_request_values(cls, method: str):
14941494
# their parents.
14951495
substr = f"__metadata_request__{method}"
14961496
for base_class in reversed(inspect.getmro(cls)):
1497-
for attr, value in vars(base_class).items():
1497+
# Copy is needed with free-threaded context to avoid
1498+
# RuntimeError: dictionary changed size during iteration.
1499+
# copy.deepcopy applied on an instance of base_class adds
1500+
# __slotnames__ attribute to base_class.
1501+
base_class_items = vars(base_class).copy().items()
1502+
for attr, value in base_class_items:
14981503
# we don't check for equivalence since python prefixes attrs
14991504
# starting with __ with the `_ClassName`.
15001505
if substr not in attr:

0 commit comments

Comments
 (0)