Skip to content

Conversation

anqixu
Copy link

@anqixu anqixu commented May 29, 2025

Currently, if a field with type-hint Optional[Type] has a non-optional default value, there's no way to set it to None by parsing from the command line. E.g.

@dataclass
class Config2:
    var_with_default: Optional[int] = 42
$ ./run.py --var_with_default None

This PR adds this feature, specifically by parsing the string literal "None" into None for optional-typed fields.

@anqixu
Copy link
Author

anqixu commented Jun 21, 2025

@lebrice could you kindly have a review of the updated PR? Previous version failed CI due to silly issue (comparing type() directly), which I since fixed.

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