Skip to content

Conversation

@AvigailRoyzenberg
Copy link

Problem

Python scripts using Enum types don't generate proper UI dropdowns. Instead:

  • Enum parameters show as generic text inputs (treated as object type)
  • Docstring descriptions are ignored (all fields show empty "")
  • Users must manually configure dropdowns for every enum parameter
class Color(str, Enum):
    RED = 'red'
    GREEN = 'green'

def main(color: Color = Color.RED):
    """
    Args:
        color (Color): Select a color
    """
    pass

Current schema (broken):

{
  "color": {
    "type": "object",
    "description": ""
  }
}

Solution

Parse Enum class definitions and docstrings to generate proper schemas:

New schema (fixed):

{
  "color": {
    "type": "string",
    "enum": ["red", "green", "blue"],
    "description": "Select a color"
  }
}

Changes

  • Extract Enum class definitions and values from Python AST
  • Parse docstring Args: sections for parameter descriptions
  • Map Enum types to string enums instead of treating as resources
  • Handle Enum.VALUE default values correctly

Testing

Added test_parse_python_sig_enum covering all functionality. All tests pass.

…ions

- Extract Enum class definitions and their string values
- Parse docstring Args: sections for parameter descriptions
- Map Enum type annotations to string enums with proper values
- Handle Enum.VALUE default values correctly
- Store descriptions in Arg.otyp field
- Add test case for enum with docstring parsing
@github-actions
Copy link
Contributor

github-actions bot commented Dec 17, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@AvigailRoyzenberg
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Dec 17, 2025
- Combine enum extraction and docstring parsing into single AST pass (2x performance improvement)
- Add support for IntEnum, StrEnum, Flag, IntFlag types
- Fix default values to use actual enum values (e.g., 'red') instead of member names (e.g., 'RED')
- Improve docstring parsing robustness with proper indentation tracking
- Clean up code structure with EnumInfo type for better maintainability

All tests pass. This addresses code review feedback for performance and correctness.
Copy link
Contributor

@rubenfiszel rubenfiszel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool, thanks, but this parses the whole code as AST everytime which can be slow and worse it does it everytime, regardless of there is an enum or not.

3 things that can be used:

  • do it lazily (but do it once) only parse metadata if we arrive to a situation where there is an unrecognized type
  • only parse the code if a keyword is present in the code (Enum here but can be made more precise), no need to parse the ast if that's not present
  • when parsing the ast, do a prepass to try remove everyhing that is not interesting (for instance, filter everything that is not class or within the class block)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants