crates/ty_python_semantic/resources/mdtest/diagnostics/missing_argument.md
If a non-union callable is called with a required parameter missing, we add a subdiagnostic showing where the parameter was defined. We don't do this for unions as we currently emit a separate diagnostic for each element of the union; having a sub-diagnostic for each element would probably be too verbose for it to be worth it.
module.py:
def f(a, b=42): ...
def g(a, b): ...
class Foo:
def method(self, a): ...
main.py:
from module import f, g, Foo
f() # snapshot
def coinflip() -> bool:
return True
h = f if coinflip() else g
# snapshot: missing-argument
# snapshot: missing-argument
h(b=56)
Foo().method() # snapshot: missing-argument
error[missing-argument]: No argument provided for required parameter `a` of function `f`
--> src/main.py:3:1
|
3 | f() # snapshot
| ^^^
|
info: Parameter declared here
--> src/module.py:1:7
|
1 | def f(a, b=42): ...
| ^
|
error[missing-argument]: No argument provided for required parameter `a` of function `f`
--> src/main.py:12:1
|
12 | h(b=56)
| ^^^^^^^
|
info: Union variant `def f(a, b=42) -> Unknown` is incompatible with this call site
info: Attempted to call union type `(def f(a, b=42) -> Unknown) | (def g(a, b) -> Unknown)`
error[missing-argument]: No argument provided for required parameter `a` of function `g`
--> src/main.py:12:1
|
12 | h(b=56)
| ^^^^^^^
|
info: Union variant `def g(a, b) -> Unknown` is incompatible with this call site
info: Attempted to call union type `(def f(a, b=42) -> Unknown) | (def g(a, b) -> Unknown)`
error[missing-argument]: No argument provided for required parameter `a` of bound method `Foo.method`
--> src/main.py:14:1
|
14 | Foo().method() # snapshot: missing-argument
| ^^^^^^^^^^^^^^
|
info: Parameter declared here
--> src/module.py:5:22
|
5 | def method(self, a): ...
| ^
|