New GitHub issue #119294 from MatthewFam:<br>

<hr>

<pre>
# Bug report

### Bug description:

I am using mypy to type-check my code and running into the following error each time I try to use an eager task factory to run my asynchronous tasks: 
```
error: Argument 1 to "set_task_factory" of "AbstractEventLoop" has incompatible type "Callable[[AbstractEventLoop | None, Coroutine[Any, Any, _T_co], DefaultNamedArg(str | None, 'name'), DefaultNamedArg(Context | None, 'context')], Task[_T_co]]"; expected "_TaskFactory | None"  [arg-type]
```

I don't think I should be getting this error given that I copied the line in question, as seen below, directly from the [the asyncio documentation](https://docs.python.org/3/library/asyncio-task.html#eager-task-factory). It seems indicative of a typing inconsistency within the source code.
```python
asyncio.get_running_loop().set_task_factory(asyncio.eager_task_factory)`
```

I've done some initial exploration to get to the bottom of this, to no avail. I tried manually checking all of the types being returned by the different parts of the problematic line of code. The docstrings and type-hinting overlays in my IDE confirm something weird is going on while the lack of type-hinting in the source code made it difficult to dig deeper.

I've also went back to the [source code](https://github.com/python/cpython/blob/e870c852c0ea96fa4e4569e9c39c7ceb80ce858d/Lib/asyncio/tasks.py#L1007). This inspired me to replace `asyncio.eager_task_factory` with its stand-in `create_eager_task_factory(Task)`. The error slightly changed, returning the following:

```
error: Argument 1 to "set_task_factory" of "AbstractEventLoop" has incompatible type "_EagerTaskFactoryType[Any]"; expected "_TaskFactory | None"  [arg-type]
note: Following member(s) of "_EagerTaskFactoryType[Any]" have conflicts:
note:     Expected:
note:         def [_T] __call__(self, AbstractEventLoop, Coroutine[Any, Any, _T] | Generator[Any, None, _T], /) -> Future[_T]
note:     Got:
note:         def __call__(self, loop: AbstractEventLoop, coro: Coroutine[Any, Any, Any], *, name: str | None = ..., context: Context | None = ...) -> Any
```

I also attempted to explicitly get the running event loop, assign it to a variable, and then set the eager task factory there—inspired by [asyncio's unit-test setup](https://github.com/python/cpython/blob/e870c852c0ea96fa4e4569e9c39c7ceb80ce858d/Lib/test/test_asyncio/test_eager_task_factory.py#L42). Once again, I faced the same issue.



### CPython versions tested on:

3.12

### Operating systems tested on:

macOS
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/119294">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>