Skip to content

Invalid diagnostic location for a sub-call to a specialized ParamSpec #2198

@dhruvmanila

Description

@dhruvmanila

Summary

Given the following example:

from typing import Callable

def fn(a: int) -> None: ...

def foo[**P, T](fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs): ...

foo(fn, a="a")

The diagnostic is using the location for fn for highlighting on foo:

ty check .                                                          
error[invalid-argument-type]: Argument to function `foo` is incorrect
  --> main.py:10:5
   |
10 | foo(fn, a="a")
   |     ^^ Expected `int`, found `Literal["a"]`
   |
info: Function defined here
 --> main.py:7:5
  |
7 | def foo[**P, T](fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs): ...
  |     ^^^         ------------------ Parameter declared here
  |
info: rule `invalid-argument-type` is enabled by default

Found 1 diagnostic
  1. The "Expected ..., found ..." should be on "a"
  2. It should use the fn function directly for the info diagnostic of "Function defined here"
  3. And, provide a sub-diagnostic / info to state that this function comes from the argument being matched against a ParamSpec type variable which resolved to this function

Version

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdiagnosticsRelated to reporting of diagnostics.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions