You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Per our discussion at Charm Tech daily sync today, we'd like to simplify the various pebble enum types from Union[EnumType | str] to just EnumType, for example, ServiceInfo.current now has type Union[ServiceStatus, str], which can be awkward for us (and for charms) to deal with.
The original reason I made them |str was so that if a charm is deployed to a newer version of Juju, which has a newer version of Pebble that add a new value to the enum, code won't fail when the enum is being created. To create the value we have code like this:
But that means code that uses these fields have to have awkward types and sometimes have to do awkward things like use(info.current) if isinstance(info.current, str) else use(info.current.value).
So we'd like to simplify the type of these to just the enum type, for example just ServiceStatus in this example.
To avoid the charm code raising an exception, we want to add a new value UNKNOWN = 'unknown' to all the enum types that are used in this way. If we got an invalid or unknown string value from Pebble, we'd set it to that instead, and give a warning. The code to create the value from Pebble JSON would become something like:
try:
current=ServiceStatus(d['current'])
exceptValueError:
warnings.warn(f'Unknown ServiceStatus value {d["current"]!r}')
current=ServiceStatus.UNKNOWN
(Note that FileType already has an UNKNOWN value, which is handy.)
The text was updated successfully, but these errors were encountered:
Per our discussion at Charm Tech daily sync today, we'd like to simplify the various pebble enum types from
Union[EnumType | str]
to justEnumType
, for example,ServiceInfo.current
now has typeUnion[ServiceStatus, str]
, which can be awkward for us (and for charms) to deal with.The original reason I made them
|str
was so that if a charm is deployed to a newer version of Juju, which has a newer version of Pebble that add a new value to the enum, code won't fail when the enum is being created. To create the value we have code like this:But that means code that uses these fields have to have awkward types and sometimes have to do awkward things like
use(info.current) if isinstance(info.current, str) else use(info.current.value)
.So we'd like to simplify the type of these to just the enum type, for example just
ServiceStatus
in this example.To avoid the charm code raising an exception, we want to add a new value
UNKNOWN = 'unknown'
to all the enum types that are used in this way. If we got an invalid or unknown string value from Pebble, we'd set it to that instead, and give a warning. The code to create the value from Pebble JSON would become something like:(Note that
FileType
already has anUNKNOWN
value, which is handy.)The text was updated successfully, but these errors were encountered: