Skip to content

Fix CliPositionalArg[list[CustomType]] crash for custom types#839

Merged
hramezani merged 1 commit intomainfrom
fix/cli-positional-arg-custom-type
Apr 7, 2026
Merged

Fix CliPositionalArg[list[CustomType]] crash for custom types#839
hramezani merged 1 commit intomainfrom
fix/cli-positional-arg-custom-type

Conversation

@hramezani
Copy link
Copy Markdown
Member

Summary

  • Fix CliPositionalArg[list[CustomType]] crashing when the custom type's validator raises a non-ValidationError exception (e.g. plain Exception, ValueError, TypeError)
  • The _merged_list_to_str method probes the inner type by calling validate_python(['1']) — if this fails for any reason, the safe fallback is is_num_type_str = None. Widened the except clause from (StopIteration, ValidationError) to Exception
  • Added regression test with a custom str subclass that raises plain Exception

Fixes #823

Test plan

  • New test test_cli_variadic_positional_arg_custom_type passes
  • All 177 existing CLI tests pass (176 + 1 new)
  • CI passes

🤖 Generated with Claude Code

…non-ValidationError exceptions

The `_merged_list_to_str` method probes the inner list type by calling
`validate_python(['1'])`, but only caught `StopIteration` and `ValidationError`.
Custom type validators can raise arbitrary exceptions (e.g. plain `Exception`),
causing a `SettingsError` instead of falling back gracefully.

Widen the except clause to catch `Exception` since this is a type-probing
heuristic where any failure should safely fall back to `is_num_type_str = None`.

Fixes #823

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hramezani hramezani force-pushed the fix/cli-positional-arg-custom-type branch from 8e74cd6 to 1a1dca8 Compare April 6, 2026 11:27
@hramezani hramezani merged commit 2355bc5 into main Apr 7, 2026
20 checks passed
@hramezani hramezani deleted the fix/cli-positional-arg-custom-type branch April 7, 2026 07:04
@hramezani hramezani mentioned this pull request Apr 20, 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.

Can't have a CliPositionalArg[list[CustomType]]

1 participant