Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions crates/core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3435,6 +3435,36 @@ fn python_match_simple_assignment() {
.unwrap();
}

#[test]
fn python_match_type_predicate_on_return_annotation() {
// Regression test for https://github.com/biomejs/gritql/issues/424
//
// In Python, return type annotations are wrapped in a `type` node. Snippets like `List` must
// be parsable in that context so `$type <: `List`` can match.
run_test_match({
TestArg {
pattern: r#"
|engine marzano(0.1)
|language python
|
|`def matching_method($_) -> $type:
| $body` where {
| $type <: `List`
| }
|"#
.trim_margin()
.unwrap(),
source: r#"
|def matching_method(x) -> List:
| return x
|"#
.trim_margin()
.unwrap(),
}
})
.unwrap();
}

#[test]
fn javascript_match_simple_assignment() {
run_test_match({
Expand Down
3 changes: 3 additions & 0 deletions crates/language/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ impl Language for Python {
("{ ", " }"),
("", "\ndef GRIT_FUNCTION():\n return;"),
("GRIT_FN(", ")"),
// Allow snippets to be parsed in return type annotation position, so we can match
// metavariables bound to Python `type` nodes (e.g. `$type <: `List``).
("def GRIT_FUNCTION() -> ", ":\n pass"),
]
}

Expand Down
Loading