Skip to content

Feature: able to parse Optional[Type] field to None from command-line #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

1 participant