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

Support Enum._missing_ hooks #532

Merged
merged 1 commit into from Aug 24, 2023
Merged

Support Enum._missing_ hooks #532

merged 1 commit into from Aug 24, 2023

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Aug 24, 2023

This adds support for Enum._missing_ hooks. This method is part of the standard library's enum implementation, and is called when a value isn't one defined directly on the Enum type. The method should return a valid enum member, or None if the value is invalid.

This may be used to support case-insensitive enums, or to coerce unknown values into a single "UNKNOWN" member.

Fixes #531.

This adds support for `Enum._missing_` hooks. This method is part of
the standard library's `enum` implementation, and is called when a value
isn't one defined directly on the `Enum` type. The method should return
a valid enum member, or `None` if the value is invalid.

This may be used to support case-insensitive enums, or to coerce unknown
values into a single "UNKNOWN" member.
@jcrist jcrist merged commit b37f0c5 into main Aug 24, 2023
8 checks passed
@jcrist jcrist deleted the enum-missing-support branch August 24, 2023 06:03
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.

Enums: Support for default member / __missing__
1 participant