Functional API breaks mypy with Never type #555

Closed
opened 2026-02-20 17:40:42 -05:00 by yindo · 1 comment
Owner

Originally created by @RustamIbragimov on GitHub (Apr 2, 2025).

Originally assigned to: @casparb on GitHub.

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

import asyncio

from langgraph.func import entrypoint, task


@task
async def my_task(number: int) -> int:
    return number + 1


@entrypoint()
async def my_workflow(number: int) -> int:
    return await my_task(number)


print(asyncio.run(my_workflow.ainvoke(1)))

Error Message and Stack Trace (if applicable)

(.venv) ➜  langgraph_test mypy main.py                     
main.py:6: error: Argument 1 to "task" has incompatible type "Callable[[int], Coroutine[Any, Any, int]]"; expected "Callable[[VarArg(Never), KwArg(Never)], Awaitable[Never]] | Callable[[VarArg(Never), KwArg(Never)], Never]"  [arg-type]
main.py:13: error: Argument 1 to "my_task" has incompatible type "int"; expected "Never"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Description

  • I'm trying to use Functional API in my project and it seems to break mypy.
  • It looks like the task decorator changes all the input types to Never.

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041
Python Version: 3.11.9 (v3.11.9:de54cf5be3, Apr 2 2024, 07:12:50) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information

langchain_core: 0.3.49
langsmith: 0.1.146
langgraph_sdk: 0.1.59

Optional packages not installed

langserve

Other Dependencies

httpx: 0.28.1
jsonpatch<2.0,>=1.33: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
orjson: 3.10.16
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.10.6
pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.3
requests-toolbelt: 1.0.0
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.

Originally created by @RustamIbragimov on GitHub (Apr 2, 2025). Originally assigned to: @casparb on GitHub. ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python import asyncio from langgraph.func import entrypoint, task @task async def my_task(number: int) -> int: return number + 1 @entrypoint() async def my_workflow(number: int) -> int: return await my_task(number) print(asyncio.run(my_workflow.ainvoke(1))) ``` ### Error Message and Stack Trace (if applicable) ```shell (.venv) ➜ langgraph_test mypy main.py main.py:6: error: Argument 1 to "task" has incompatible type "Callable[[int], Coroutine[Any, Any, int]]"; expected "Callable[[VarArg(Never), KwArg(Never)], Awaitable[Never]] | Callable[[VarArg(Never), KwArg(Never)], Never]" [arg-type] main.py:13: error: Argument 1 to "my_task" has incompatible type "int"; expected "Never" [arg-type] Found 2 errors in 1 file (checked 1 source file) ``` ### Description * I'm trying to use Functional API in my project and it seems to break mypy. * It looks like the task decorator changes all the input types to Never. ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041 > Python Version: 3.11.9 (v3.11.9:de54cf5be3, Apr 2 2024, 07:12:50) [Clang 13.0.0 (clang-1300.0.29.30)] Package Information ------------------- > langchain_core: 0.3.49 > langsmith: 0.1.146 > langgraph_sdk: 0.1.59 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > httpx: 0.28.1 > jsonpatch<2.0,>=1.33: Installed. No version info available. > langsmith<0.4,>=0.1.125: Installed. No version info available. > orjson: 3.10.16 > packaging<25,>=23.2: Installed. No version info available. > pydantic: 2.10.6 > pydantic<3.0.0,>=2.5.2;: Installed. No version info available. > pydantic<3.0.0,>=2.7.4;: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.3 > requests-toolbelt: 1.0.0 > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available.
yindo added the bugtype checking labels 2026-02-20 17:40:42 -05:00
yindo closed this issue 2026-02-20 17:40:42 -05:00
Author
Owner

@eyurtsev commented on GitHub (Apr 2, 2025):

Related to https://github.com/langchain-ai/langgraph/issues/3310

@eyurtsev commented on GitHub (Apr 2, 2025): Related to https://github.com/langchain-ai/langgraph/issues/3310
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#555