Skip to content

subiquity.common.serialize: add a way to have a "non-exhaustive" enum#1984

Merged
mwhudson merged 4 commits intocanonical:mainfrom
mwhudson:non-exhaustive-enums
May 5, 2024
Merged

subiquity.common.serialize: add a way to have a "non-exhaustive" enum#1984
mwhudson merged 4 commits intocanonical:mainfrom
mwhudson:non-exhaustive-enums

Conversation

@mwhudson
Copy link
Collaborator

relates to #1980

Copy link
Member

@dbungert dbungert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Looks fine, one open question, and a rebase to cleanup commits please.

mwhudson added 4 commits May 3, 2024 17:49
We use the subiquity.common.api stuff to talk to snapd, and use
enumerations to describe several field names. This is a bit of a
landmine in some situations because snapd can add a value to the set of
possible return values and thus cause serialization to fail. Rather than
just giving up on all of the typo-resistance of declaring enums for API
types, this adds a way to mark an enumeration as "non-exhaustive":
values that are part of the declared enum will be deserialized as values
of the enum but values that are not will be passed straight through (as
strings, in all the cases used in snapdapi.py), which conveniently will
never compare equal to an enumeration. This should let us just declare
the values of the enumerations we actually care about and not break if
we don't declare every value snapd actually uses.
@mwhudson mwhudson force-pushed the non-exhaustive-enums branch from fed2f10 to e3f16aa Compare May 3, 2024 05:49
@mwhudson
Copy link
Collaborator Author

mwhudson commented May 3, 2024

I rebased and cleaned up one bit of logic to hopefully more comprehensible. I don't see the open question though?

Copy link
Member

@dbungert dbungert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I think I confused this with the other PR where I was suggesting to document one more possible state in the enum. LGTM, thanks!

@mwhudson mwhudson merged commit 771fc13 into canonical:main May 5, 2024
@mwhudson
Copy link
Collaborator Author

mwhudson commented May 5, 2024

I should tag @d-loose so he knows about the change in capabilities of the API here -- basically a dict with enum keys is serialized as an object, not a list of key, value pairs. there are no such types in the subiquity API today though.

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