{"record":{"id":"d17f018146bc17fd","repo":"huggingface/transformers","slug":"type-resolution-failed-for-dtype-try-declaring","errorCode":null,"errorMessage":"Type resolution failed for {dtype}. Try declaring the class in global scope or removing line of `from __future__ import annotations` which opts in Postponed Evaluation of Annotations (PEP 563)","messagePattern":"Type resolution failed for (.+?)\\. Try declaring the class in global scope or removing line of `from __future__ import annotations` which opts in Postponed Evaluation of Annotations \\(PEP 563\\)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/transformers/hf_argparser.py","lineNumber":260,"sourceCode":"            bool_kwargs[\"default\"] = False\n            parser.add_argument(\n                f\"--no_{field.name}\",\n                f\"--no-{field.name.replace('_', '-')}\",\n                action=\"store_false\",\n                dest=field.name,\n                **bool_kwargs,\n            )\n\n    def _add_dataclass_arguments(self, dtype: DataClassType):\n        if hasattr(dtype, \"_argument_group_name\"):\n            parser = self.add_argument_group(dtype._argument_group_name)\n        else:\n            parser = self\n\n        try:\n            type_hints: dict[str, type] = get_type_hints(dtype)\n        except NameError:\n            raise RuntimeError(\n                f\"Type resolution failed for {dtype}. Try declaring the class in global scope or \"\n                \"removing line of `from __future__ import annotations` which opts in Postponed \"\n                \"Evaluation of Annotations (PEP 563)\"\n            )\n\n        for field in dataclasses.fields(dtype):\n            if not field.init:\n                continue\n            field.type = type_hints[field.name]\n            self._parse_dataclass_field(parser, field)\n\n    def parse_args_into_dataclasses(\n        self,\n        args=None,\n        return_remaining_strings=False,\n        look_for_args_file=True,\n        args_filename=None,\n        args_file_flag=None,","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/hf_argparser.py#L242-L278","documentation":"Error \"Type resolution failed for {dtype}. Try declaring the class in global scope or removing line of `from __future__ import annotations` which opts in Postponed Evaluation of Annotations (PEP 563)\" thrown in huggingface/transformers.","triggerScenarios":"Raised in HfArgumentParser when get_type_hints fails to resolve a field's annotation.","commonSituations":"Dataclass declared in a local scope or with 'from __future__ import annotations' referencing names unavailable at parse time.","solutions":["Remove `from __future__ import annotations` from the file defining the dataclass.","Define the type at module global scope so it can be resolved."],"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-15T17:31:12.345Z"}