ty_python_semantic: add union type context to function call type errors

This context gets added only when calling a function through a union
type.
This commit is contained in:
Andrew Gallant 2025-05-09 09:58:18 -04:00 committed by Andrew Gallant
parent 5ea3a52c8a
commit 346e82b572
42 changed files with 235 additions and 101 deletions

View file

@ -12,7 +12,7 @@ X = GenericAlias(type, ())
A = NewType("A", int)
# TODO: typeshed for `typing.GenericAlias` uses `type` for the first argument. `NewType` should be special-cased
# to be compatible with `type`
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `type`, found `NewType`"
# error: [invalid-argument-type] "Argument to function `__new__` is incorrect: Expected `type`, found `NewType`"
B = GenericAlias(A, ())
def _(

View file

@ -9,8 +9,8 @@ def _(c: Callable[[], int]):
def _(c: Callable[[int, str], int]):
reveal_type(c(1, "a")) # revealed: int
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["a"]`"
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[1]`"
# error: [invalid-argument-type] "Argument is incorrect: Expected `int`, found `Literal["a"]`"
# error: [invalid-argument-type] "Argument is incorrect: Expected `str`, found `Literal[1]`"
reveal_type(c("a", 1)) # revealed: int
```

View file

@ -85,7 +85,7 @@ class C:
c = C()
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to bound method `__call__` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(c("foo")) # revealed: int
```
@ -99,7 +99,7 @@ class C:
c = C()
# error: 13 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `C`"
# error: 13 [invalid-argument-type] "Argument to bound method `__call__` is incorrect: Expected `int`, found `C`"
reveal_type(c()) # revealed: int
```

View file

@ -99,8 +99,8 @@ def _(flag: bool) -> None:
def __new__(cls, x: int, y: int = 1): ...
reveal_type(Foo(1)) # revealed: Foo
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["1"]`"
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["1"]`"
# error: [invalid-argument-type] "Argument to function `__new__` is incorrect: Expected `int`, found `Literal["1"]`"
# error: [invalid-argument-type] "Argument to function `__new__` is incorrect: Expected `int`, found `Literal["1"]`"
reveal_type(Foo("1")) # revealed: Foo
# error: [missing-argument] "No argument provided for required parameter `x` of function `__new__`"
# error: [missing-argument] "No argument provided for required parameter `x` of function `__new__`"
@ -232,8 +232,8 @@ def _(flag: bool) -> None:
def __init__(self, x: int, y: int = 1): ...
reveal_type(Foo(1)) # revealed: Foo
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["1"]`"
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["1"]`"
# error: [invalid-argument-type] "Argument to bound method `__init__` is incorrect: Expected `int`, found `Literal["1"]`"
# error: [invalid-argument-type] "Argument to bound method `__init__` is incorrect: Expected `int`, found `Literal["1"]`"
reveal_type(Foo("1")) # revealed: Foo
# error: [missing-argument] "No argument provided for required parameter `x` of bound method `__init__`"
# error: [missing-argument] "No argument provided for required parameter `x` of bound method `__init__`"

View file

@ -77,7 +77,7 @@ def _(flag: bool):
def f(x: int) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(f("foo")) # revealed: int
```
@ -87,7 +87,7 @@ reveal_type(f("foo")) # revealed: int
def f(x: int, /) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(f("foo")) # revealed: int
```
@ -97,7 +97,7 @@ reveal_type(f("foo")) # revealed: int
def f(*args: int) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(f("foo")) # revealed: int
```
@ -107,7 +107,7 @@ reveal_type(f("foo")) # revealed: int
def f(x: int) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(f(x="foo")) # revealed: int
```
@ -117,7 +117,7 @@ reveal_type(f(x="foo")) # revealed: int
def f(*, x: int) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(f(x="foo")) # revealed: int
```
@ -127,7 +127,7 @@ reveal_type(f(x="foo")) # revealed: int
def f(**kwargs: int) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
reveal_type(f(x="foo")) # revealed: int
```
@ -137,8 +137,8 @@ reveal_type(f(x="foo")) # revealed: int
def f(x: int = 1, y: str = "foo") -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[2]`"
# error: 20 [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["bar"]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `str`, found `Literal[2]`"
# error: 20 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["bar"]`"
reveal_type(f(y=2, x="bar")) # revealed: int
```

View file

@ -115,7 +115,7 @@ inspect.getattr_static()
# error: [missing-argument] "No argument provided for required parameter `attr`"
inspect.getattr_static(C())
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[1]`"
# error: [invalid-argument-type] "Argument to function `getattr_static` is incorrect: Expected `str`, found `Literal[1]`"
inspect.getattr_static(C(), 1)
# error: [too-many-positional-arguments] "Too many positional arguments to function `getattr_static`: expected 3, got 4"

View file

@ -24,7 +24,7 @@ to the valid order:
def f(**kw: int, x: str) -> int:
return 1
# error: 15 [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[1]`"
# error: 15 [invalid-argument-type] "Argument to function `f` is incorrect: Expected `str`, found `Literal[1]`"
reveal_type(f(1)) # revealed: int
```
@ -38,7 +38,7 @@ def f(x: int = 1, y: str) -> int:
return 1
reveal_type(f(y="foo")) # revealed: int
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["foo"]`"
# error: [invalid-argument-type] "Argument to function `f` is incorrect: Expected `int`, found `Literal["foo"]`"
# error: [missing-argument] "No argument provided for required parameter `y` of function `f`"
reveal_type(f("foo")) # revealed: int
```

View file

@ -350,7 +350,7 @@ class D:
# This function is wrongly annotated, it should be `type[D]` instead of `D`
pass
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `D`, found `<class 'D'>`"
# error: [invalid-argument-type] "Argument to bound method `f` is incorrect: Expected `D`, found `<class 'D'>`"
D.f()
```

View file

@ -20,7 +20,7 @@ class C:
def _(subclass_of_c: type[C]):
reveal_type(subclass_of_c(1)) # revealed: C
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["a"]`"
# error: [invalid-argument-type] "Argument to bound method `__init__` is incorrect: Expected `int`, found `Literal["a"]`"
reveal_type(subclass_of_c("a")) # revealed: C
# error: [missing-argument] "No argument provided for required parameter `x` of bound method `__init__`"
reveal_type(subclass_of_c()) # revealed: C

View file

@ -94,7 +94,7 @@ def _(flag: bool):
else:
f = f2
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[3]`"
# error: [invalid-argument-type] "Argument to function `f2` is incorrect: Expected `str`, found `Literal[3]`"
x = f(3)
reveal_type(x) # revealed: int | str
```

View file

@ -207,7 +207,7 @@ first argument:
def wrong_signature(f: int) -> str:
return "a"
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `def f(x) -> Unknown`"
# error: [invalid-argument-type] "Argument to function `wrong_signature` is incorrect: Expected `int`, found `def f(x) -> Unknown`"
@wrong_signature
def f(x): ...

View file

@ -99,9 +99,9 @@ def _(n: int):
else:
f = PossiblyNotCallable()
# error: [too-many-positional-arguments]
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[3]`"
# error: [invalid-argument-type] "Argument to function `f2` is incorrect: Expected `str`, found `Literal[3]`"
# error: [missing-argument]
# error: [invalid-argument-type] "Argument to this function is incorrect: Argument type `Literal[3]` does not satisfy upper bound of type variable `T`"
# error: [invalid-argument-type] "Argument to function `f4` is incorrect: Argument type `Literal[3]` does not satisfy upper bound of type variable `T`"
# error: [call-non-callable] "Object of type `Literal[5]` is not callable"
# error: [no-matching-overload]
# error: [call-non-callable] "Object of type `PossiblyNotCallable` is not callable (possibly unbound `__call__` method)"

View file

@ -42,7 +42,7 @@ def f(w: Wrapper) -> None:
v: int | None = w.value
# This function call is incorrect, because `w.value` could be `None`. We therefore emit the following
# error: "Argument to this function is incorrect: Expected `int`, found `Unknown | None`"
# error: "Argument to function `accepts_int` is incorrect: Expected `int`, found `Unknown | None`"
c = accepts_int(w.value)
```

View file

@ -123,11 +123,11 @@ reveal_type(Bounded[int]()) # revealed: Bounded[int]
reveal_type(Bounded[IntSubclass]()) # revealed: Bounded[IntSubclass]
# TODO: update this diagnostic to talk about type parameters and specializations
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `str`"
# error: [invalid-argument-type] "Argument to class `Bounded` is incorrect: Expected `int`, found `str`"
reveal_type(Bounded[str]()) # revealed: Unknown
# TODO: update this diagnostic to talk about type parameters and specializations
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `int | str`"
# error: [invalid-argument-type] "Argument to class `Bounded` is incorrect: Expected `int`, found `int | str`"
reveal_type(Bounded[int | str]()) # revealed: Unknown
reveal_type(BoundedByUnion[int]()) # revealed: BoundedByUnion[int]
@ -156,7 +156,7 @@ reveal_type(Constrained[str]()) # revealed: Constrained[str]
reveal_type(Constrained[int | str]()) # revealed: Constrained[int | str]
# TODO: update this diagnostic to talk about type parameters and specializations
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int | str`, found `object`"
# error: [invalid-argument-type] "Argument to class `Constrained` is incorrect: Expected `int | str`, found `object`"
reveal_type(Constrained[object]()) # revealed: Unknown
```

View file

@ -98,11 +98,11 @@ reveal_type(Bounded[int]()) # revealed: Bounded[int]
reveal_type(Bounded[IntSubclass]()) # revealed: Bounded[IntSubclass]
# TODO: update this diagnostic to talk about type parameters and specializations
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `str`"
# error: [invalid-argument-type] "Argument to class `Bounded` is incorrect: Expected `int`, found `str`"
reveal_type(Bounded[str]()) # revealed: Unknown
# TODO: update this diagnostic to talk about type parameters and specializations
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `int | str`"
# error: [invalid-argument-type] "Argument to class `Bounded` is incorrect: Expected `int`, found `int | str`"
reveal_type(Bounded[int | str]()) # revealed: Unknown
reveal_type(BoundedByUnion[int]()) # revealed: BoundedByUnion[int]
@ -129,7 +129,7 @@ reveal_type(Constrained[str]()) # revealed: Constrained[str]
reveal_type(Constrained[int | str]()) # revealed: Constrained[int | str]
# TODO: update this diagnostic to talk about type parameters and specializations
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int | str`, found `object`"
# error: [invalid-argument-type] "Argument to class `Constrained` is incorrect: Expected `int | str`, found `object`"
reveal_type(Constrained[object]()) # revealed: Unknown
```

View file

@ -84,7 +84,7 @@ class C[T]:
c: C[int] = C[int]()
c.m1(1)
c.m2(1)
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `int`, found `Literal["string"]`"
# error: [invalid-argument-type] "Argument to bound method `m2` is incorrect: Expected `int`, found `Literal["string"]`"
c.m2("string")
```

View file

@ -146,7 +146,7 @@ class C:
@property
def attr(self) -> int:
return 1
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `(Any, Any, /) -> None`, found `def attr(self) -> None`"
# error: [invalid-argument-type] "Argument to bound method `setter` is incorrect: Expected `(Any, Any, /) -> None`, found `def attr(self) -> None`"
@attr.setter
def attr(self) -> None:
pass
@ -156,7 +156,7 @@ class C:
```py
class C:
# error: [invalid-argument-type] "Argument to this function is incorrect: Expected `((Any, /) -> Any) | None`, found `def attr(self, x: int) -> int`"
# error: [invalid-argument-type] "Argument to class `property` is incorrect: Expected `((Any, /) -> Any) | None`, found `def attr(self, x: int) -> int`"
@property
def attr(self, x: int) -> int:
return 1

View file

@ -68,7 +68,7 @@ info[revealed-type]: Revealed type
```
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f` is incorrect
--> src/mdtest_snippet.py:12:15
|
10 | reveal_type(f(True)) # revealed: Literal[True]

View file

@ -83,7 +83,7 @@ info[revealed-type]: Revealed type
```
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f` is incorrect
--> src/mdtest_snippet.py:13:15
|
11 | reveal_type(f(None)) # revealed: None

View file

@ -65,7 +65,7 @@ info[revealed-type]: Revealed type
```
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f` is incorrect
--> src/mdtest_snippet.py:9:15
|
7 | reveal_type(f(True)) # revealed: Literal[True]

View file

@ -80,7 +80,7 @@ info[revealed-type]: Revealed type
```
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f` is incorrect
--> src/mdtest_snippet.py:10:15
|
8 | reveal_type(f(None)) # revealed: None

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:5
|
2 | return x * x

View file

@ -23,7 +23,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to bound method `square` is incorrect
--> src/mdtest_snippet.py:6:10
|
5 | c = C()

View file

@ -27,7 +27,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:3:13
|
1 | import package

View file

@ -22,7 +22,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:2:9
|
1 | def bar():

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:8
|
2 | return x * y * z

View file

@ -25,7 +25,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:8:8
|
6 | return x * y * z

View file

@ -24,7 +24,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:7:5
|
5 | # error: [invalid-argument-type]
@ -44,7 +44,7 @@ info: `invalid-argument-type` is enabled by default
```
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:7:10
|
5 | # error: [invalid-argument-type]
@ -64,7 +64,7 @@ info: `invalid-argument-type` is enabled by default
```
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:7:15
|
5 | # error: [invalid-argument-type]

View file

@ -20,7 +20,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `loads` is incorrect
--> src/mdtest_snippet.py:3:12
|
1 | import json

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:11
|
2 | return x * y * z

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:11
|
2 | return x * y * z

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:11
|
2 | return x * y * z

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:8
|
2 | return x * y * z

View file

@ -23,7 +23,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to bound method `__call__` is incorrect
--> src/mdtest_snippet.py:6:3
|
5 | c = C()

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:14
|
2 | return len(numbers)

View file

@ -21,7 +21,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_argu
# Diagnostics
```
error[invalid-argument-type]: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `foo` is incorrect
--> src/mdtest_snippet.py:4:20
|
2 | return len(numbers)

View file

@ -31,7 +31,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.m
# Diagnostics
```
error: lint:invalid-argument-type: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f2` is incorrect
--> src/mdtest_snippet.py:14:11
|
12 | # error: [too-many-positional-arguments]
@ -48,12 +48,14 @@ info: Function defined here
| ^^ --------- Parameter declared here
5 | return 0
|
info: `lint:invalid-argument-type` is enabled by default
info: Union variant `def f2(name: str) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int)`
info: `invalid-argument-type` is enabled by default
```
```
error: lint:too-many-positional-arguments: Too many positional arguments to function `f1`: expected 0, got 1
error[too-many-positional-arguments]: Too many positional arguments to function `f1`: expected 0, got 1
--> src/mdtest_snippet.py:14:11
|
12 | # error: [too-many-positional-arguments]
@ -61,6 +63,8 @@ error: lint:too-many-positional-arguments: Too many positional arguments to func
14 | x = f(3)
| ^
|
info: `lint:too-many-positional-arguments` is enabled by default
info: Union variant `def f1() -> int` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int)`
info: `too-many-positional-arguments` is enabled by default
```

View file

@ -30,7 +30,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.m
# Diagnostics
```
error: lint:invalid-argument-type: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f2` is incorrect
--> src/mdtest_snippet.py:13:11
|
11 | f = f2
@ -47,6 +47,8 @@ info: Function defined here
| ^^ --------- Parameter declared here
5 | return 0
|
info: `lint:invalid-argument-type` is enabled by default
info: Union variant `def f2(name: str) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1(a: int) -> int) | (def f2(name: str) -> int)`
info: `invalid-argument-type` is enabled by default
```

View file

@ -31,7 +31,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.m
# Diagnostics
```
error: lint:parameter-already-assigned: Multiple values provided for parameter `name` of function `f1`
error[parameter-already-assigned]: Multiple values provided for parameter `name` of function `f1`
--> src/mdtest_snippet.py:14:18
|
12 | # error: [parameter-already-assigned]
@ -39,12 +39,14 @@ error: lint:parameter-already-assigned: Multiple values provided for parameter `
14 | y = f("foo", name="bar", unknown="quux")
| ^^^^^^^^^^
|
info: `lint:parameter-already-assigned` is enabled by default
info: Union variant `def f1(name: str) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1(name: str) -> int) | (def any(*args, **kwargs) -> int)`
info: `parameter-already-assigned` is enabled by default
```
```
error: lint:unknown-argument: Argument `unknown` does not match any known parameter of function `f1`
error[unknown-argument]: Argument `unknown` does not match any known parameter of function `f1`
--> src/mdtest_snippet.py:14:30
|
12 | # error: [parameter-already-assigned]
@ -52,6 +54,8 @@ error: lint:unknown-argument: Argument `unknown` does not match any known parame
14 | y = f("foo", name="bar", unknown="quux")
| ^^^^^^^^^^^^^^
|
info: `lint:unknown-argument` is enabled by default
info: Union variant `def f1(name: str) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1(name: str) -> int) | (def any(*args, **kwargs) -> int)`
info: `unknown-argument` is enabled by default
```

View file

@ -53,9 +53,9 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.m
39 | else:
40 | f = PossiblyNotCallable()
41 | # error: [too-many-positional-arguments]
42 | # error: [invalid-argument-type] "Argument to this function is incorrect: Expected `str`, found `Literal[3]`"
42 | # error: [invalid-argument-type] "Argument to function `f2` is incorrect: Expected `str`, found `Literal[3]`"
43 | # error: [missing-argument]
44 | # error: [invalid-argument-type] "Argument to this function is incorrect: Argument type `Literal[3]` does not satisfy upper bound of type variable `T`"
44 | # error: [invalid-argument-type] "Argument to function `f4` is incorrect: Argument type `Literal[3]` does not satisfy upper bound of type variable `T`"
45 | # error: [call-non-callable] "Object of type `Literal[5]` is not callable"
46 | # error: [no-matching-overload]
47 | # error: [call-non-callable] "Object of type `PossiblyNotCallable` is not callable (possibly unbound `__call__` method)"
@ -65,7 +65,7 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/union_call.m
# Diagnostics
```
error: lint:call-non-callable: Object of type `Literal[5]` is not callable
error[call-non-callable]: Object of type `Literal[5]` is not callable
--> src/mdtest_snippet.py:48:9
|
46 | # error: [no-matching-overload]
@ -73,12 +73,14 @@ error: lint:call-non-callable: Object of type `Literal[5]` is not callable
48 | x = f(3)
| ^^^^
|
info: `lint:call-non-callable` is enabled by default
info: Union variant `Literal[5]` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `call-non-callable` is enabled by default
```
```
error: lint:call-non-callable: Object of type `PossiblyNotCallable` is not callable (possibly unbound `__call__` method)
error[call-non-callable]: Object of type `PossiblyNotCallable` is not callable (possibly unbound `__call__` method)
--> src/mdtest_snippet.py:48:9
|
46 | # error: [no-matching-overload]
@ -86,12 +88,14 @@ error: lint:call-non-callable: Object of type `PossiblyNotCallable` is not calla
48 | x = f(3)
| ^^^^
|
info: `lint:call-non-callable` is enabled by default
info: Union variant `PossiblyNotCallable` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `call-non-callable` is enabled by default
```
```
error: lint:missing-argument: No argument provided for required parameter `b` of function `f3`
error[missing-argument]: No argument provided for required parameter `b` of function `f3`
--> src/mdtest_snippet.py:48:9
|
46 | # error: [no-matching-overload]
@ -99,12 +103,14 @@ error: lint:missing-argument: No argument provided for required parameter `b` of
48 | x = f(3)
| ^^^^
|
info: `lint:missing-argument` is enabled by default
info: Union variant `def f3(a: int, b: int) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `missing-argument` is enabled by default
```
```
error: lint:no-matching-overload: No overload of method wrapper `__get__` of function `f` matches arguments
error[no-matching-overload]: No overload of method wrapper `__get__` of function `f` matches arguments
--> src/mdtest_snippet.py:48:9
|
46 | # error: [no-matching-overload]
@ -112,12 +118,14 @@ error: lint:no-matching-overload: No overload of method wrapper `__get__` of fun
48 | x = f(3)
| ^^^^
|
info: `lint:no-matching-overload` is enabled by default
info: Union variant `<method-wrapper `__get__` of `f`>` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `no-matching-overload` is enabled by default
```
```
error: lint:invalid-argument-type: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f2` is incorrect
--> src/mdtest_snippet.py:48:11
|
46 | # error: [no-matching-overload]
@ -134,12 +142,14 @@ info: Function defined here
| ^^ --------- Parameter declared here
7 | return 0
|
info: `lint:invalid-argument-type` is enabled by default
info: Union variant `def f2(name: str) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `invalid-argument-type` is enabled by default
```
```
error: lint:invalid-argument-type: Argument to this function is incorrect
error[invalid-argument-type]: Argument to function `f4` is incorrect
--> src/mdtest_snippet.py:48:11
|
46 | # error: [no-matching-overload]
@ -156,12 +166,14 @@ info: Type variable defined here
| ^^^^^^
13 | return 0
|
info: `lint:invalid-argument-type` is enabled by default
info: Union variant `def f4(x: T) -> int` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `invalid-argument-type` is enabled by default
```
```
error: lint:too-many-positional-arguments: Too many positional arguments to function `f1`: expected 0, got 1
error[too-many-positional-arguments]: Too many positional arguments to function `f1`: expected 0, got 1
--> src/mdtest_snippet.py:48:11
|
46 | # error: [no-matching-overload]
@ -169,6 +181,8 @@ error: lint:too-many-positional-arguments: Too many positional arguments to func
48 | x = f(3)
| ^
|
info: `lint:too-many-positional-arguments` is enabled by default
info: Union variant `def f1() -> int` is incompatible with this call site
info: Attempted to call union type `(def f1() -> int) | (def f2(name: str) -> int) | (def f3(a: int, b: int) -> int) | (def f4(x: T) -> int) | Literal[5] | Unknown | (<method-wrapper `__get__` of `f`>) | PossiblyNotCallable`
info: `too-many-positional-arguments` is enabled by default
```