Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Add error context for extra callable parameters#25269

Merged
sharkdp merged 1 commit into
mainfrom
david/extra-param-ctx
May 20, 2026
Merged

[ty] Add error context for extra callable parameters#25269
sharkdp merged 1 commit into
mainfrom
david/extra-param-ctx

Conversation

@sharkdp

@sharkdp sharkdp commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

In an invalid assignment like the following ...

def source(x: int, extra: str) -> bool: ...

target: Callable[[int], bool] = source

... we now add a new error context hint (last line):

error[invalid-assignment]: Object of type `def source(x: int, extra: str) -> bool` is not assignable to `(int, /) -> bool`
  --> src/mdtest_snippet.py:16:9
   |
16 | target: Callable[[int], bool] = source  # snapshot
   |         ---------------------   ^^^^^^ Incompatible value of type `def source(x: int, extra: str) -> bool`
   |         |
   |         Declared type
   |
info: unexpected extra parameter `extra`

Test Plan

New Markdown test

@sharkdp sharkdp added ty Multi-file analysis & type inference diagnostics Related to reporting of diagnostics. labels May 20, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from charliermarsh May 20, 2026 09:32
@sharkdp sharkdp force-pushed the david/extra-param-ctx branch from d0a51a1 to 041b8ae Compare May 20, 2026 09:34
@astral-sh-bot

astral-sh-bot Bot commented May 20, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134.

@astral-sh-bot

astral-sh-bot Bot commented May 20, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 20, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

}
Self::ExtraRequiredParameter { parameter } => match parameter {
ParameterDescription::Named(name) => format!("unexpected extra parameter `{name}`"),
ParameterDescription::Index(_) => "unexpected extra parameter".to_string(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option<Cow<...>> :)

(I assume you will reject this feedback lol)

@charliermarsh charliermarsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks.

@sharkdp sharkdp merged commit eff7996 into main May 20, 2026
60 checks passed
@sharkdp sharkdp deleted the david/extra-param-ctx branch May 20, 2026 09:58
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
## Summary

In an invalid assignment like the following ...

```py
def source(x: int, extra: str) -> bool: ...

target: Callable[[int], bool] = source
```

... we now add a new error context hint (last line):

```
error[invalid-assignment]: Object of type `def source(x: int, extra: str) -> bool` is not assignable to `(int, /) -> bool`
  --> src/mdtest_snippet.py:16:9
   |
16 | target: Callable[[int], bool] = source  # snapshot
   |         ---------------------   ^^^^^^ Incompatible value of type `def source(x: int, extra: str) -> bool`
   |         |
   |         Declared type
   |
info: unexpected extra parameter `extra`
```

## Test Plan

New Markdown test
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request May 28, 2026
## Summary

In an invalid assignment like the following ...

```py
def source(x: int, extra: str) -> bool: ...

target: Callable[[int], bool] = source
```

... we now add a new error context hint (last line):

```
error[invalid-assignment]: Object of type `def source(x: int, extra: str) -> bool` is not assignable to `(int, /) -> bool`
  --> src/mdtest_snippet.py:16:9
   |
16 | target: Callable[[int], bool] = source  # snapshot
   |         ---------------------   ^^^^^^ Incompatible value of type `def source(x: int, extra: str) -> bool`
   |         |
   |         Declared type
   |
info: unexpected extra parameter `extra`
```

## Test Plan

New Markdown test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants