Incorrect type of key in `PreviewParam` for representing a key that may not be present

Open
#608 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Read transform_loader_params.py at the PreviewParam definition linked in the issue. Verify the type represents each key as omittable while allowing either None or its stated value type, and confirm all three intended cases are covered.

Written by the indexing model from the issue text.

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):
https://github.com/DiamondLightSource/httomo/blob/584e15ccd84fbd7f440454b6d3c48a071b8f2f83/httomo/transform_loader_params.py#L48-L55

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 None or 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 None or the T

which I think is accomplished with NotRequired[Optional[T]].

Dominant language
Python
Stars
10
Forks
5
Avg merge
5d 17h
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DiamondLightSource/httomo

All issues in DiamondLightSource/httomo

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.