Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type-hint in UI layer's check_valid_ref_id() function #474

Open
yousefmoazzam opened this issue Oct 10, 2024 · 0 comments
Open
Labels
minor Nice to do but not vital refactor

Comments

@yousefmoazzam
Copy link
Collaborator

The function is the following:

httomo/httomo/ui_layer.py

Lines 241 to 263 in 7842bae

def check_valid_ref_id(
side_str: str, ref_id: str, v: str, method: MethodWrapper
) -> None:
"""Check the reference values are valid
TODO option to relocate to yaml_checker
Parameters
----------
side_str
side output string
ref_id
reference id
v
ref value
method
method found from ref
"""
if side_str != "side_outputs":
raise ValueError(
"Config error: output references must be of the form <id>.side_outputs.<name>"
)
if method is None:
raise ValueError(f"could not find method referenced by {ref_id} in {v}")

Pyright complains about the body of the second if statement, saying the following:

Type analysis indicates code is unreachable

This is understandable, because the type of method in the function signature is MethodWrapper, and so should never be None. Thus, the condition in the if statement will never evaluate to True, and the body will never be executed.

One way to easily fix this is by making method have type Optional[MethodWrapper]. However, some investigation into whether it should ever be None (and possibly investigation in further refactorings in other logic in the UI layer) may be wise before opting for the simplest fix.

@yousefmoazzam yousefmoazzam added minor Nice to do but not vital refactor labels Oct 10, 2024
@yousefmoazzam yousefmoazzam changed the title Fix incorrect type-hint in UI layer's check_valid_ref_id() function Incorrect type-hint in UI layer's check_valid_ref_id() function Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Nice to do but not vital refactor
Projects
None yet
Development

No branches or pull requests

1 participant