c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Reoccurring pattern of usage `try-except`

Open ovaar opened this issue 4 years ago • 0 comments

Describe the issue

I just came across the extensive usage of the following pattern, see screenshot, try-except to check whether a key exists in a dictionary. I want to propose the usage of configuration validators or use strictly defined record types such as dataclasses-json.

This can be re-written to the following to be more explicit and readable to the user.

if not "algorithm" in cfg:
  raise ...

algorithm_name = cfg["algorithm"]
if not algorithm_name in algorithms:
  raise ...

There is also a typo: Unkown should be Unknown in C3:ERROR:Unkown sampling method

Screenshots

image

ovaar avatar Apr 20 '21 10:04 ovaar