{"record":{"id":"ea2d30efee9ac419","repo":"Unity-Technologies/ml-agents","slug":"str-not-implemented-for-type-self-class","errorCode":null,"errorMessage":"__str__ not implemented for type {self.__class__}.","messagePattern":"__str__ not implemented for type (.+?)\\.","errorType":"exception","errorClass":"TrainerConfigError","httpStatus":null,"severity":"warning","filePath":"ml-agents/mlagents/trainers/settings.py","lineNumber":279,"sourceCode":"        _mapping = {\n            ParameterRandomizationType.UNIFORM: UniformSettings,\n            ParameterRandomizationType.GAUSSIAN: GaussianSettings,\n            ParameterRandomizationType.MULTIRANGEUNIFORM: MultiRangeUniformSettings,\n            ParameterRandomizationType.CONSTANT: ConstantSettings\n            # Constant type is handled if a float is provided instead of a config\n        }\n        return _mapping[self]\n\n\n@attr.s(auto_attribs=True)\nclass ParameterRandomizationSettings(abc.ABC):\n    seed: int = parser.get_default(\"seed\")\n\n    def __str__(self) -> str:\n        \"\"\"\n        Helper method to output sampler stats to console.\n        \"\"\"\n        raise TrainerConfigError(f\"__str__ not implemented for type {self.__class__}.\")\n\n    @staticmethod\n    def structure(\n        d: Union[Mapping, float], t: type\n    ) -> \"ParameterRandomizationSettings\":\n        \"\"\"\n        Helper method to a ParameterRandomizationSettings class. Meant to be registered with\n        cattr.register_structure_hook() and called with cattr.structure(). This is needed to handle\n        the special Enum selection of ParameterRandomizationSettings classes.\n        \"\"\"\n        if isinstance(d, (float, int)):\n            return ConstantSettings(value=d)\n        if not isinstance(d, Mapping):\n            raise TrainerConfigError(\n                f\"Unsupported parameter randomization configuration {d}.\"\n            )\n        if \"sampler_type\" not in d:\n            raise TrainerConfigError(","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/settings.py#L261-L297","documentation":"ParameterRandomizationSettings explicitly overrides `__str__` to raise this TrainerConfigError, so stringifying any parameter-randomization settings object fails. It exists to force callers to output sampler stats through a dedicated mechanism rather than implicit str()/print(). Hitting it means code called str() or f-string formatting on a settings object.","triggerScenarios":"Calling `str(param_settings)`, printing a ParameterRandomizationSettings instance, or embedding it in an f-string / logging call.","commonSituations":"Debug logging of the environment parameter randomization config, or generic config dump code that formats every settings object as a string.","solutions":["Log individual fields (e.g. `settings.sampler_type`, `settings.sampler_parameters`) instead of the whole object.","Use the library's sampler stats output path (environment parameter channel / stats recorder) for console output.","Remove or guard the debug print that stringifies the settings object."],"exampleFix":"// before\nprint(f\"Randomization settings: {param_settings}\")\n\n// after\nprint(f\"Randomization settings: {param_settings.sampler_type} {param_settings.sampler_parameters}\")","handlingStrategy":"try-catch","validationCode":"if isinstance(obj, ParameterRandomizationSettings):\n    logger.info('%s', attr.asdict(obj))\nelse:\n    logger.info('%s', obj)","typeGuard":"def is_randomization_settings(obj) -> bool:\n    return isinstance(obj, ParameterRandomizationSettings)","tryCatchPattern":"try:\n    desc = str(settings)\nexcept TrainerConfigError:\n    desc = repr(attr.asdict(settings))","preventionTips":["Never print settings objects directly; dump their fields with attrs.asdict","Use logging with structured fields instead of f-strings on config objects","Review custom debug hooks that stringify all config objects"],"tags":["api-misuse","parameter-randomization","string-formatting"],"backgroundTag":"operation-not-supported","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}