python-trio / trio-typing

Type hints for Trio and related projects
Other
27 stars 13 forks source link

Clock argument of run can be None #58

Closed domsekotill closed 2 years ago

domsekotill commented 2 years ago

Trio's documentations explicitly states that the "clock" argument of trio.run can be None:

  • clockNone to use the default system-specific monotonic clock; otherwise, an object implementing the trio.abc.Clock interface, like (for example) a trio.testing.MockClock instance.

however the stub for it is showing only trio.abc.Clock:

https://github.com/python-trio/trio-typing/blob/9d57cb1d3f1fa7c9f915e7c884e9a2930645b8b7/trio-stubs/__init__.pyi#L166-L173

This is making it problematic to wrap run with a similar calling interface:

from trio import run
from trio.abc import Clock

def my_run(clock: Clock|None = None) -> None:
    run(my_async_fn, clock=clock)

async def my_async_fn() -> None:
   ...
$ mypy sample.py
sample.py:5: error: Argument "clock" to "run" has incompatible type "Optional[Clock]"; expected "Clock"
Found 1 error in 1 file (checked 1 source file)