-
Notifications
You must be signed in to change notification settings - Fork 5
Description
PreviewParam is intended to represent the python dict that is the value of the preview parameter in a loader's config (if the preview parameter value is given at all, it can also be None):
httomo/httomo/transform_loader_params.py
Lines 48 to 55 in 584e15c
| class PreviewParam(TypedDict): | |
| """ | |
| Preview configuration dict. | |
| """ | |
| angles: Optional[StartStopEntry] | |
| detector_y: Optional[PreviewParamEntry] | |
| detector_x: Optional[PreviewParamEntry] |
The intention in the definition of the type was that any of the keys could be omitted. However, due to the use of the Optional type, in its current state, the PreviewParam type states that:
- all three keys must be present in the dict
- the value of the keys can be either
Noneor some other type
which isn't what was intended.
The Optional type alone is not the correct type for what is desired.
The NotRequired type provides a piece of the puzzle.
However, NotRequired[T] isn't quite correct either. This is because NotRequired[T] disallows setting the key's value to None, which is allowed.
The correct type should allow:
- omitting of a key
- but also providing the key as either
Noneor theT
which I think is accomplished with NotRequired[Optional[T]].