Investigate whether Optional
members of ops/pebble.py
TypedDict
s can be NotRequired
instead
#1405
Labels
investigate
Needs further investigation - do we want to do this?
low priority
Non-urgent issue we may (or may not) consider later
small item
type hints
Several
TypedDict
s inops/pebble.py
represent values returned from Pebble. Generally pebble will simply omit an optional field if it is not set (but we need to confirm this for each one). Due to limitations of typing on older Python versions, theseTypedDict
s sometimes usetotal=False
to coarsely describe this, as well as annotating some values asOptional
(i.e. can beNone
).There are two components here.
NotRequired
fromtyping_extensions
cleanly while supporting older python versions, e.g. putting theNotRequired
import behindif TYPE_CHECKING
and using stringified type annotations? This would allow us to explicitly mark which keys are required and which are not instead of usingtotal=False
.TypedDict
s, is it a supported pattern for users to passNone
as a synonym for the entry being missing? When a dict only comes from Pebble, we can useNotRequired[some_type]
, but when a dict can be constructed by a user, we may need/want to useNotRequired[Optional[some_type]]
instead to let them useNone
for values they don't want to set.Related: investigate the use of
Optional
values inCheck
.CheckDict
has severalOptional
members which will simply be missing if they're not set when coming from Pebble. TheCheck
constructor annotates these values asOptional
, but sets some of them to empty strings instead if they're missing.Check.to_dict
then filters out anyFalse
y values, including empty strings andNone
. This may be a good opportunity to tidy this up a little bit.The text was updated successfully, but these errors were encountered: