-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dcreager/overloads
* main: [red-knot] Rework `Type::to_instance()` to return `Option<Type>` (#16428) [red-knot] Add tests asserting that `KnownClass::to_instance()` doesn't unexpectedly fallback to `Type::Unknown` with full typeshed stubs (#16608) [red-knot] Handle gradual intersection types in assignability (#16611) [red-knot] mypy_primer: split installation and execution (#16622) [red-knot] mypy_primer: pipeline improvements (#16620) [red-knot] Infer `lambda` expression (#16547) [red-knot] mypy_primer: strip ANSI codes (#16604) [red-knot] mypy_primer: comment on PRs (#16599)
- Loading branch information
Showing
13 changed files
with
663 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: PR comment (mypy_primer) | ||
|
||
on: # zizmor: ignore[dangerous-triggers] | ||
workflow_run: | ||
workflows: [Run mypy_primer] | ||
types: [completed] | ||
workflow_dispatch: | ||
inputs: | ||
workflow_run_id: | ||
description: The mypy_primer workflow that triggers the workflow run | ||
required: true | ||
|
||
jobs: | ||
comment: | ||
runs-on: ubuntu-24.04 | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- uses: dawidd6/action-download-artifact@v8 | ||
name: Download PR number | ||
with: | ||
name: pr-number | ||
run_id: ${{ github.event.workflow_run.id || github.event.inputs.workflow_run_id }} | ||
if_no_artifact_found: ignore | ||
allow_forks: true | ||
|
||
- name: Parse pull request number | ||
id: pr-number | ||
run: | | ||
if [[ -f pr-number ]] | ||
then | ||
echo "pr-number=$(<pr-number)" >> "$GITHUB_OUTPUT" | ||
fi | ||
- uses: dawidd6/action-download-artifact@v8 | ||
name: "Download mypy_primer results" | ||
id: download-mypy_primer_diff | ||
if: steps.pr-number.outputs.pr-number | ||
with: | ||
name: mypy_primer_diff | ||
workflow: mypy_primer.yaml | ||
pr: ${{ steps.pr-number.outputs.pr-number }} | ||
path: pr/mypy_primer_diff | ||
workflow_conclusion: completed | ||
if_no_artifact_found: ignore | ||
allow_forks: true | ||
|
||
- name: Generate comment content | ||
id: generate-comment | ||
if: steps.download-mypy_primer_diff.outputs.found_artifact == 'true' | ||
run: | | ||
# Guard against malicious mypy_primer results that symlink to a secret | ||
# file on this runner | ||
if [[ -L pr/mypy_primer_diff/mypy_primer.diff ]] | ||
then | ||
echo "Error: mypy_primer.diff cannot be a symlink" | ||
exit 1 | ||
fi | ||
# Note this identifier is used to find the comment to update on | ||
# subsequent runs | ||
echo '<!-- generated-comment mypy_primer -->' >> comment.txt | ||
echo '## `mypy_primer` results' >> comment.txt | ||
if [ -s "pr/mypy_primer_diff/mypy_primer.diff" ]; then | ||
echo '<details>' >> comment.txt | ||
echo '<summary>Changes were detected when running on open source projects</summary>' >> comment.txt | ||
echo '' >> comment.txt | ||
echo '```diff' >> comment.txt | ||
cat pr/mypy_primer_diff/mypy_primer.diff >> comment.txt | ||
echo '```' >> comment.txt | ||
echo '</details>' >> comment.txt | ||
else | ||
echo 'No ecosystem changes detected ✅' >> comment.txt | ||
fi | ||
echo 'comment<<EOF' >> "$GITHUB_OUTPUT" | ||
cat comment.txt >> "$GITHUB_OUTPUT" | ||
echo 'EOF' >> "$GITHUB_OUTPUT" | ||
- name: Find existing comment | ||
uses: peter-evans/find-comment@v3 | ||
if: steps.generate-comment.outcome == 'success' | ||
id: find-comment | ||
with: | ||
issue-number: ${{ steps.pr-number.outputs.pr-number }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: "<!-- generated-comment mypy_primer -->" | ||
|
||
- name: Create or update comment | ||
if: steps.find-comment.outcome == 'success' | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
issue-number: ${{ steps.pr-number.outputs.pr-number }} | ||
body-path: comment.txt | ||
edit-mode: replace |
100 changes: 100 additions & 0 deletions
100
crates/red_knot_python_semantic/resources/mdtest/expression/lambda.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# `lambda` expression | ||
|
||
## No parameters | ||
|
||
`lambda` expressions can be defined without any parameters. | ||
|
||
```py | ||
reveal_type(lambda: 1) # revealed: () -> @Todo(lambda return type) | ||
|
||
# error: [unresolved-reference] | ||
reveal_type(lambda: a) # revealed: () -> @Todo(lambda return type) | ||
``` | ||
|
||
## With parameters | ||
|
||
Unlike parameters in function definition, the parameters in a `lambda` expression cannot be | ||
annotated. | ||
|
||
```py | ||
reveal_type(lambda a: a) # revealed: (a) -> @Todo(lambda return type) | ||
reveal_type(lambda a, b: a + b) # revealed: (a, b) -> @Todo(lambda return type) | ||
``` | ||
|
||
But, it can have default values: | ||
|
||
```py | ||
reveal_type(lambda a=1: a) # revealed: (a=Literal[1]) -> @Todo(lambda return type) | ||
reveal_type(lambda a, b=2: a) # revealed: (a, b=Literal[2]) -> @Todo(lambda return type) | ||
``` | ||
|
||
And, positional-only parameters: | ||
|
||
```py | ||
reveal_type(lambda a, b, /, c: c) # revealed: (a, b, /, c) -> @Todo(lambda return type) | ||
``` | ||
|
||
And, keyword-only parameters: | ||
|
||
```py | ||
reveal_type(lambda a, *, b=2, c: b) # revealed: (a, *, b=Literal[2], c) -> @Todo(lambda return type) | ||
``` | ||
|
||
And, variadic parameter: | ||
|
||
```py | ||
reveal_type(lambda *args: args) # revealed: (*args) -> @Todo(lambda return type) | ||
``` | ||
|
||
And, keyword-varidic parameter: | ||
|
||
```py | ||
reveal_type(lambda **kwargs: kwargs) # revealed: (**kwargs) -> @Todo(lambda return type) | ||
``` | ||
|
||
Mixing all of them together: | ||
|
||
```py | ||
# revealed: (a, b, /, c=Literal[True], *args, *, d=Literal["default"], e=Literal[5], **kwargs) -> @Todo(lambda return type) | ||
reveal_type(lambda a, b, /, c=True, *args, d="default", e=5, **kwargs: None) | ||
``` | ||
|
||
## Parameter type | ||
|
||
In addition to correctly inferring the `lambda` expression, the parameters should also be inferred | ||
correctly. | ||
|
||
Using a parameter with no default value: | ||
|
||
```py | ||
lambda x: reveal_type(x) # revealed: Unknown | ||
``` | ||
|
||
Using a parameter with default value: | ||
|
||
```py | ||
lambda x=1: reveal_type(x) # revealed: Unknown | Literal[1] | ||
``` | ||
|
||
Using a variadic paramter: | ||
|
||
```py | ||
# TODO: should be `tuple[Unknown, ...]` (needs generics) | ||
lambda *args: reveal_type(args) # revealed: tuple | ||
``` | ||
|
||
Using a keyword-varidic parameter: | ||
|
||
```py | ||
# TODO: should be `dict[str, Unknown]` (needs generics) | ||
lambda **kwargs: reveal_type(kwargs) # revealed: dict | ||
``` | ||
|
||
## Nested `lambda` expressions | ||
|
||
Here, a `lambda` expression is used as the default value for a parameter in another `lambda` | ||
expression. | ||
|
||
```py | ||
reveal_type(lambda a=lambda x, y: 0: 2) # revealed: (a=(x, y) -> @Todo(lambda return type)) -> @Todo(lambda return type) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.