{"record":{"id":"0194d19929955555","repo":"huggingface/transformers","slug":"unresolved-type-detected-which-should-have-been-d","errorCode":null,"errorMessage":"Unresolved type detected, which should have been done with the help of `typing.get_type_hints` method by default","messagePattern":"Unresolved type detected, which should have been done with the help of `typing\\.get_type_hints` method by default","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/transformers/hf_argparser.py","lineNumber":159,"sourceCode":"        self.dataclass_types = list(dataclass_types)\n        for dtype in self.dataclass_types:\n            self._add_dataclass_arguments(dtype)\n\n    @staticmethod\n    def _parse_dataclass_field(parser: ArgumentParser, field: dataclasses.Field):\n        # Long-option strings are conventionlly separated by hyphens rather\n        # than underscores, e.g., \"--long-format\" rather than \"--long_format\".\n        # Argparse converts hyphens to underscores so that the destination\n        # string is a valid attribute name. Hf_argparser should do the same.\n        long_options = [f\"--{field.name}\"]\n        if \"_\" in field.name:\n            long_options.append(f\"--{field.name.replace('_', '-')}\")\n\n        kwargs = field.metadata.copy()\n        # field.metadata is not used at all by Data Classes,\n        # it is provided as a third-party extension mechanism.\n        if isinstance(field.type, str):\n            raise RuntimeError(\n                \"Unresolved type detected, which should have been done with the help of \"\n                \"`typing.get_type_hints` method by default\"\n            )\n\n        aliases = kwargs.pop(\"aliases\", [])\n        if isinstance(aliases, str):\n            aliases = [aliases]\n\n        origin_type = getattr(field.type, \"__origin__\", field.type)\n        if origin_type is Union or (hasattr(types, \"UnionType\") and isinstance(origin_type, types.UnionType)):\n            if str not in field.type.__args__ and (\n                len(field.type.__args__) != 2 or type(None) not in field.type.__args__\n            ):\n                raise ValueError(\n                    \"Only `Union[X, NoneType]` (i.e., `Optional[X]`) is allowed for `Union` because\"\n                    \" the argument parser only supports one type per argument.\"\n                    f\" Problem encountered in field '{field.name}'.\"\n                )","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/hf_argparser.py#L141-L177","documentation":"Error \"Unresolved type detected, which should have been done with the help of `typing.get_type_hints` method by default\" thrown in huggingface/transformers.","triggerScenarios":"Raised in HfArgumentParser when a dataclass field type remains an unresolved string/ForwardRef after get_type_hints.","commonSituations":"Dataclass fields annotated with types not importable at parse time or left as strings under postponed annotation evaluation.","solutions":["Avoid unresolved/forward-reference types in the dataclass; use concrete types.","Call `typing.get_type_hints` or move the referenced type into scope."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}