ahvn.utils.basic.debug_utils module¶
- ahvn.utils.basic.debug_utils.value_match(supported, got, thres=0.3)[source]¶
Find similar values from a list of supported values, returning matches sorted by similarity score.
- Parameters:
- Returns:
- A list of (value, score) tuples sorted by score descending.
Only includes values with similarity >= thres.
- Return type:
- ahvn.utils.basic.debug_utils.raise_mismatch(supported, got, name='value', mode='raise', comment=None, thres=0.3)[source]¶
Raise an error if the value is not in the list of supported values, suggesting the closest match.
- Parameters:
supported (List[Any]) – A list of supported values.
got (Any) – The value to check against the supported list.
name (str) – The name of the value for error messages. Defaults to ‘value’.
mode (Literal['ignore','match','warn','exit','raise']) – The mode of handling the mismatch. - ‘ignore’: Do nothing.Directly returns the original value if no close match is found. - ‘match’: Do nothing. Directly returns the suggestion if a close match is found. - ‘warn’: Log a warning message. Returns the suggestion if a close match is found. - ‘exit’: Log an error message and exit the program with status 1. - ‘raise’: Raise a ValueError with the error message. Defaults to ‘raise’.
comment (Optional[str]) – An optional comment to include in the error message. Defaults to None.
thres (float) – The threshold for similarity to consider a suggestion valid. Defaults to 0.3.
- Returns:
- The suggested value if a close match is found and mode is ‘warn’. Otherwise, returns None.
If got is in supported, does nothing and returns got.
- Return type:
- Raises:
ValueError – If the value is not in the supported list and the mode is ‘raise’.
NotImplementedError – If an unknown mode is provided.
- ahvn.utils.basic.debug_utils.error_str(err=None, tb=True)[source]¶
Get a string representation of an error, optionally including the traceback.
- exception ahvn.utils.basic.debug_utils.DependencyError[source]¶
Bases:
ImportError