use-callable-ellipsis

Prefer Callable[…, T] for callable types with arbitrary parameters.

Message

Use Callable[…, T] instead of Callable[[…], T].

Valid examples

from typing import Callable
x: Callable[[int], int]
from typing import Callable
x: Callable[[int, int, ...], int]
from typing import Callable
x: Callable
Show more
from typing import Callable as C
x: C[..., int] = ...
from typing import Callable
def foo(bar: Optional[Callable[..., int]]) -> Callable[..., int]:
    ...
import typing as t
x: t.Callable[..., int] = ...
from typing import Callable
x: Callable[..., int] = ...
from typing import Callable
C = Callable

class C:
    def __class_getitem__(cls, item):
        return cls

x: C[[...], int] = ...

Invalid examples

from typing import Callable
x: Callable[[...], int] = ...

Suggested fix

from typing import Callable
x: Callable[..., int] = ...
Show more
import typing as t
x: t.Callable[[...], int] = ...

Suggested fix

import typing as t
x: t.Callable[..., int] = ...
from typing import Callable as C
x: C[[...], int] = ...

Suggested fix

from typing import Callable as C
x: C[..., int] = ...
from typing import Callable
def foo(bar: Optional[Callable[[...], int]]) -> Callable[[...], int]:
    ...

Suggested fix

from typing import Callable
def foo(bar: Optional[Callable[..., int]]) -> Callable[..., int]:
    ...
from collections.abc import Callable
x: Callable[[...], int] = ...

Suggested fix

from collections.abc import Callable
x: Callable[..., int] = ...
from typing import Callable
C = Callable
x: C[[...], int] = ...

Suggested fix

from typing import Callable
C = Callable
x: C[..., int] = ...
from typing import Callable
C = OtherC = Callable
x: OtherC[[...], int] = ...

Suggested fix

from typing import Callable
C = OtherC = Callable
x: OtherC[..., int] = ...
from typing import *
x: Callable[[...], int] = ...

Suggested fix

from typing import *
x: Callable[..., int] = ...