SuggestionDict

class bpod_core.misc.SuggestionDict

Bases: dict[str, ~V]

A dictionary that suggests similar keys on failed lookup.

On KeyError, raises error_class with a message that includes the closest match from the existing keys via suggest_similar(), making typos and near-misses easier to diagnose.

Parameters:
  • dictionary (MutableMapping) – Initial key-value pairs.

  • name (str, default: 'key') – Human-readable label for the key type used in the error message.

  • error_class (type of Exception, default: KeyError) – Exception class to raise on failed lookup. Must accept a single string argument.

Examples

>>> d = SuggestionDict({'Port1': 1, 'Port2': 2}, name='channel')
>>> d['Port1']
1
>>> d['Prot1']
Traceback (most recent call last):
    ...
KeyError: "No such channel: 'Prot1' - did you mean 'Port1'?"