Skip to content

fix: resolve Enum default value resolution when parameter callbacks are present#1870

Closed
Hootsworth wants to merge 1 commit into
fastapi:masterfrom
Hootsworth:fix-enum-callback-default
Closed

fix: resolve Enum default value resolution when parameter callbacks are present#1870
Hootsworth wants to merge 1 commit into
fastapi:masterfrom
Hootsworth:fix-enum-callback-default

Conversation

@Hootsworth

Copy link
Copy Markdown

Description

This PR resolves a silent bug in Typer where an Enum option with a custom parameter callback resolves to None instead of its default Enum member value when the option is not explicitly passed in the CLI.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Added tests for new functionality

Related Issues

Fixes silent default value loss on Enum options when callbacks are present.

Changes Made

  • typer/main.py: Updated generate_enum_convertor to immediately return the value if it is already an instance of the target Enum class (which is the case when Click passes the default Enum member when the option is omitted).
  • tests/test_types.py: Added test_enum_with_callback to verify that Enum options with default values and custom callbacks correctly resolve to their default Enum members when omitted on the CLI.

Testing

  • Added test_enum_with_callback to the test suite.
  • Ran full pytest test suite (1345 passed, 0 failed).

@Hootsworth Hootsworth closed this Jul 1, 2026
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