Skip to content

Stubtest whines about Concatenate given as Callable argument #12825

Closed
@JulienPalard

Description

@JulienPalard

With the concatenate example from the typing doc, which works with mypy 0.950, if I split it to a file and a stub, stubtest starts to compain about Concatenate being used as a Callable argument:

totest.py:

from threading import Lock

# Use this lock to ensure that only one thread is executing a function
# at any time.
my_lock = Lock()

def with_lock(f):
    '''A decorator which provides a lock.'''
    def inner(*args, **kwargs):
        # Provide the lock as the first argument.
        return f(my_lock, *args, **kwargs)
    return inner

@with_lock
def sum_threadsafe(lock, numbers):
    '''Add a list of numbers together in a thread-safe manner.'''
    with lock:
        return sum(numbers)

# We don't need to pass in the lock ourselves thanks to the decorator.
sum_threadsafe([1.1, 2.2, 3.3])

totest.pyi:

from threading import Lock
from typing import Concatenate, ParamSpec, TypeVar, Callable

P = ParamSpec('P')
R = TypeVar('R')


def with_lock(f: Callable[Concatenate[Lock, P], R]) -> Callable[P, R]: ...

stubtest run:

$ stubtest totest
error: not checking stubs due to mypy build errors:
totest.pyi:8: error: The first argument to Callable must be a list of types or "..."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions