ahvn.utils.basic.debug_utils module¶
- ahvn.utils.basic.debug_utils.value_match(supported, got, thres=0.3)[源代码]¶
Find similar values from a list of supported values, returning matches sorted by similarity score.
- 参数:
- 返回:
- A list of (value, score) tuples sorted by score descending.
Only includes values with similarity >= thres.
- 返回类型:
- ahvn.utils.basic.debug_utils.raise_mismatch(supported, got, name='value', mode='raise', comment=None, thres=0.3)[源代码]¶
Raise an error if the value is not in the list of supported values, suggesting the closest match.
- 参数:
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.
- 返回:
- 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.
- 返回类型:
- 抛出:
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)[源代码]¶
Get a string representation of an error, optionally including the traceback.
- exception ahvn.utils.basic.debug_utils.DependencyError[源代码]¶
基类:
ImportError