DiamondLightSource / httomo

High-throughput tomography pipeline
https://diamondlightsource.github.io/httomo/
Other
5 stars 4 forks source link

Fix incorrect type-hints in `yaml_generator._set_param_value()` signature #253

Closed yousefmoazzam closed 6 months ago

yousefmoazzam commented 6 months ago

The inspect.signature() function returns a Signature, and is used in the YAML generator here: https://github.com/DiamondLightSource/httomo/blob/d9afc1f04e29a375cee17d33033d75f47a99da34/templates/yaml_templates_generator.py#L71-L73

Signature.parameters is of type Parameter. Iterating over a Parameters value like in yaml_generator.py: https://github.com/DiamondLightSource/httomo/blob/d9afc1f04e29a375cee17d33033d75f47a99da34/templates/yaml_templates_generator.py#L80

will be iterating over key-value pairs where:

The key and value in that loop is passed to the _set_value_param() function: https://github.com/DiamondLightSource/httomo/blob/d9afc1f04e29a375cee17d33033d75f47a99da34/templates/yaml_templates_generator.py#L100-L106

but the type-hints for the key and value are incorrect.

This causes static type checkers like pyright to highlight the use of v.default in that function https://github.com/DiamondLightSource/httomo/blob/d9afc1f04e29a375cee17d33033d75f47a99da34/templates/yaml_templates_generator.py#L120-L121

with the following error:

Cannot access member "default " for type "int"

Member "default" is unknown [reportAttributeAccessIssue]

because the variable v is type-hinted with the type int in the function signature.

It would be good to correct the type-hint for k and v, as well as perhaps giving them more descriptive names, such as name and value respectively.

It would also be good to update the docstring accordingly, and correct the descriptions of the k and v parameters (they're the name and value of a parameter, not of a method).