Skip to content
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

Require fields with None in their annotation to have None as their default #37

Merged
merged 3 commits into from
Jul 27, 2023

Conversation

mthuurne
Copy link
Member

TOML doesn't have a None equivalent, so we're not able to format a None value unless it is the default. Also we wouldn't be able to ever bind None to it, so user code handling None would be redundant.

Maybe this is something to revisit if we ever add JSON support, but for now I think this is an improvement over silently ignoring None values.

Closes #31

mthuurne added 3 commits July 27, 2023 02:20
We do want the `for` statement to be covered, but we don't expect the
loop to ever end naturally (only via `break`).
After thinking about the issue again, I realized that while it is
not a particularly useful thing, it's perfectly valid to have an
empty dataclass and that is a situation in which the `for` loop
would exhaust its iterator.
TOML doesn't have a `None` equivalent, so we're not able to format
a `None` value unless it is the default. Also we wouldn't be able
to ever bind `None` to it, so user code handling `None` would be
redundant.
@mthuurne mthuurne merged commit 40704c7 into main Jul 27, 2023
@mthuurne mthuurne deleted the optional-default-none branch July 27, 2023 01:21
@mthuurne mthuurne changed the title Require optional fields to have None as their default Require fields with None in their annotation to have None as their default Jul 27, 2023
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.

Handling of optional fields with non-None defaults
1 participant