{"record":{"id":"b96fdb3c04fb4346","repo":"open-mmlab/mmdetection","slug":"dataset-must-a-str-but-got-type-dataset","errorCode":null,"errorMessage":"dataset must a str, but got {type(dataset)}","messagePattern":"dataset must a str, but got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/evaluation/functional/class_names.py","lineNumber":761,"sourceCode":"    'objects365v2': ['objects365v2', 'obj365v2'],\n    'lvis': ['lvis', 'lvis_v1'],\n}\n\n\ndef get_classes(dataset) -> list:\n    \"\"\"Get class names of a dataset.\"\"\"\n    alias2name = {}\n    for name, aliases in dataset_aliases.items():\n        for alias in aliases:\n            alias2name[alias] = name\n\n    if is_str(dataset):\n        if dataset in alias2name:\n            labels = eval(alias2name[dataset] + '_classes()')\n        else:\n            raise ValueError(f'Unrecognized dataset: {dataset}')\n    else:\n        raise TypeError(f'dataset must a str, but got {type(dataset)}')\n    return labels\n","sourceCodeStart":743,"sourceCodeEnd":763,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/evaluation/functional/class_names.py#L743-L763","documentation":"get_classes requires the dataset argument to be a string; any other type (list handling happens earlier, so e.g. None, dict, int) raises TypeError.","triggerScenarios":"Calling get_classes(None), get_classes(['a','b']) that escapes earlier branches, or a config feeding a non-str value (e.g. CLASSES=None) into get_classes.","commonSituations":"Config migrations where CLASSES/`classes` kwarg becomes None or a tuple; programmatic metric construction with dynamic dataset variables.","solutions":["Pass a str dataset name or the explicit class list according to the API signature","Normalize config values: ensure classes is str or list[str]","Add an assertion/log before calling get_classes to catch bad types early"],"exampleFix":"# before\nget_classes(None)\n# after\nget_classes('coco') if isinstance(ds, str) else list(ds)","handlingStrategy":"type-guard","validationCode":"assert isinstance(dataset, str), f'dataset must be str, got {type(dataset)}'","typeGuard":"def is_dataset_str(x) -> bool:\n    return isinstance(x, str)","tryCatchPattern":"try:\n    labels = get_classes(ds)\nexcept TypeError:\n    ds = str(ds); labels = get_classes(ds)","preventionTips":["Normalize CLASSES config values before passing to metrics","Use explicit is_str checks in config loaders"],"tags":["type-error","mmdetection","dataset-name"],"backgroundTag":"invalid-argument-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}