Skip to content

Fix panics while searching type comments in function with syntax error - #78

Merged
ilevkivskyi merged 2 commits into
mainfrom
fix-panics
Aug 21, 2026
Merged

Fix panics while searching type comments in function with syntax error#78
ilevkivskyi merged 2 commits into
mainfrom
fix-panics

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Collaborator

This fixes panics found in python/mypy#21823

cc @JukkaL

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just some ideas about additional test cases.

Comment thread src/serialize_ast.rs
#[test]
fn test_syntax_error_broken_args() {
// Test that we do not panic on invalid function arguments.
let source = "def f(x, (y, z)): pass\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test also case where the invalid function definition is not the first thing in the file, e.g. there is another valid function definition on a previous line.

Comment thread src/serialize_ast.rs
#[test]
fn test_syntax_error_empty_func() {
// Test that we do not panic on invalid function definition.
let text = "def hello()\n pass\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test also case where the invalid function definition is not the first thing in the file, e.g. there is another valid function definition on a previous line.

@ilevkivskyi
ilevkivskyi merged commit 969b630 into main Aug 21, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the fix-panics branch August 21, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants