◐ Shell
clean mode source ↗

TypeError: '|' not supported between instances of '_CallableGenericAlias' and 'NoneType'

Feature

The following fails on rustpython but succeeds on cpython3.12

from collections.abc import Awaitable, Callable
from typing import TypeVar

T = TypeVar("T")

async def abort_signal_handler(
    fn: Callable[[], Awaitable[T]], on_abort: Callable[[], None] | None = None
) -> T:
    pass

Traceback (most recent call last):
File "/tmp/foo.py", line 7, in
fn: Callable[[], Awaitable[T]], on_abort: Callable[[], None] | None = None
TypeError: '|' not supported between instances of '_CallableGenericAlias' and 'NoneType'

Python Documentation or reference to CPython source code

I'm not sure. I have tried comparing RustPython's typing.py to cpython's. There are differences in the treatment of Callable.

https://github.com/python/cpython/blob/main/Lib/typing.py