-
- Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)topic-protocols
Description
To Reproduce
# mypy: enable-incomplete-feature=NewGenericSyntax from collections.abc import Callable from typing import Protocol class ActionType(Protocol): def __call__(self, var: str, context: int = 2) -> None: ... class Job[*_Ts]: def __init__(self, target: Callable[[*_Ts], None]) -> None: self.target = target def run_job[*_Ts](job: Job[*_Ts], *args: *_Ts) -> None: ... def a1(action: ActionType) -> None: job = Job(action) run_job(job, "Hello") # -> errorActual Behavior
error: Cannot infer type argument 1 of "run_job" [misc] Expected Behavior
No error. Mypy should be able to tell that context has a default value and is thus optional. It already works from pure Callables (without the intermediate generic class).
def run_job_2[*_Ts](action: Callable[[*_Ts], None], *args: *_Ts) -> None: ... def a2(action: ActionType) -> None: run_job_2(action, "Hello") # works fineYour Environment
- Mypy version used:
mypy 1.11.0+dev.177c8ee7b8166b3dcf89c034a676ef5818edbc38 (compiled: no)(current master) - Mypy command-line flags:
--enable-incomplete-feature=NewGenericSyntax(the bug exists with the old generic syntax as well) - Python version used:
3.12
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-646PEP 646 (TypeVarTuple, Unpack)PEP 646 (TypeVarTuple, Unpack)topic-protocols