Fix LocalPythonExecutor support for Enum and other metaclasses by colesmcintosh · Pull Request #1797 · huggingface/smolagents (original) (raw)

@colesmcintosh

Fixes huggingface#1795

The LocalPythonExecutor was using the generic type() function to create all classes, which fails for classes with custom metaclasses like Enum. Python's Enum metaclass requires a special _EnumDict namespace object during class creation, not a regular dict.

This fix:

This enables support for Enum and any other class that uses a custom metaclass with a __prepare__() method.

aymeric-roucher

approved these changes Oct 9, 2025

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})