{"record":{"id":"b903db00dcfe84dd","repo":"microsoft/autogen","slug":"return-type-not-found-please-use-none-as-the-ty","errorCode":null,"errorMessage":"Return type not found. Please use `None` as the type hint of the return type.","messagePattern":"Return type not found\\. Please use `None` as the type hint of the return type\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_routed_agent.py","lineNumber":256,"sourceCode":"    def decorator(\n        func: Callable[[AgentT, ReceivesT, MessageContext], Coroutine[Any, Any, None]],\n    ) -> MessageHandler[AgentT, ReceivesT, None]:\n        type_hints = get_type_hints(func)\n        if \"message\" not in type_hints:\n            raise AssertionError(\"message parameter not found in function signature\")\n\n        if \"return\" not in type_hints:\n            raise AssertionError(\"return parameter not found in function signature\")\n\n        # Get the type of the message parameter\n        target_types = get_types(type_hints[\"message\"])\n        if target_types is None:\n            raise AssertionError(\"Message type not found. Please provide a type hint for the message parameter.\")\n\n        return_types = get_types(type_hints[\"return\"])\n\n        if return_types is None:\n            raise AssertionError(\"Return type not found. Please use `None` as the type hint of the return type.\")\n\n        # Convert target_types to list and stash\n\n        @wraps(func)\n        async def wrapper(self: AgentT, message: ReceivesT, ctx: MessageContext) -> None:\n            if type(message) not in target_types:\n                if strict:\n                    raise CantHandleException(f\"Message type {type(message)} not in target types {target_types}\")\n                else:\n                    logger.warning(f\"Message type {type(message)} not in target types {target_types}\")\n\n            return_value = await func(self, message, ctx)  # type: ignore\n\n            if return_value is not None:\n                if strict:\n                    raise ValueError(f\"Return type {type(return_value)} is not None.\")\n                else:\n                    logger.warning(f\"Return type {type(return_value)} is not None. It will be ignored.\")","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_routed_agent.py#L238-L274","documentation":"The @event decorator requires the return annotation to resolve to a type, and for event handlers it must be None (events cannot produce responses). get_types() on the return hint returned None — either there is no return annotation at all, or it is an expression get_types cannot interpret (e.g. a TypeVar or unresolvable forward ref). The message tells you to use None as the return type hint.","triggerScenarios":"Handler with no '-> ...' clause, or with '-> T' / '-> \"SomeUnresolvedType\"' instead of '-> None'.","commonSituations":"Copying an @rpc handler and switching the decorator to @event without changing the return annotation; omitting the return annotation entirely; generic handler mixins with TypeVar returns.","solutions":["Change the return annotation to None: async def on_event(self, message: MyEvent, ctx: MessageContext) -> None","If you actually need to return a response to the caller, use @rpc and annotate the response message type"],"exampleFix":"# before\n@event\nasync def on_event(self, message: MyEvent, ctx: MessageContext) -> \"T\": ...\n\n# after\n@event\nasync def on_event(self, message: MyEvent, ctx: MessageContext) -> None: ...","handlingStrategy":"validation","validationCode":"from typing import get_type_hints\n\ndef event_return_is_none(func) -> bool:\n    hints = get_type_hints(func)\n    return hints.get(\"return\") is type(None) or hints.get(\"return\") is None and False or hints.get(\"return\") in (type(None),)","typeGuard":"def is_none_returning(func) -> bool:\n    return get_type_hints(func).get(\"return\") is type(None)","tryCatchPattern":null,"preventionTips":["Standardize @event handlers as '-> None' in code review checklists","Let the type checker verify handler signatures against the decorator's overloads"],"tags":["python","type-hints","decorator","autogen-core"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}