From 19236b472bbd2f298d327682a0178e91474eb5a3 Mon Sep 17 00:00:00 2001 From: Elias Date: Sun, 20 Sep 2026 15:13:11 +0800 Subject: [PATCH] Avoid goto crashes on unfinished keyword calls (#2106) --- AUTHORS.txt | 1 + jedi/inference/names.py | 2 ++ test/test_api/test_api.py | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 3ccb0a7c..1ec033a9 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -66,6 +66,7 @@ Code Contributors - Martin Vielsmaier (@moser) - TingJia Wu (@WutingjiaX) - Nguyễn Hồng Quân +- haoran3160-afk (@haoran3160-afk) And a few more "anonymous" contributors. diff --git a/jedi/inference/names.py b/jedi/inference/names.py index 53549c3d..80608068 100644 --- a/jedi/inference/names.py +++ b/jedi/inference/names.py @@ -170,6 +170,8 @@ class AbstractTreeName(AbstractNameDefinition): trailer = par.parent if trailer.type == 'arglist': trailer = trailer.parent + if trailer.type == 'error_node': + return [] if trailer.type != 'classdef': if trailer.type == 'decorator': value_set = context.infer_node(trailer.children[1]) diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 81c71199..0a3e77fa 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -231,6 +231,19 @@ def test_goto_follow_imports(Script): assert d.name == 'a' +@pytest.mark.parametrize('prefix', ['', 'def foo(bar): pass\n', 'def f():\n ']) +@pytest.mark.parametrize('call', ['foo(bar=1', 'foo(bar=1,', 'foo(foo(bar=1']) +def test_goto_incomplete_named_argument(Script, prefix, call): + code = prefix + call + column = code.splitlines()[-1].index('bar') + assert Script(code).goto(column=column) == [] + + +def test_goto_named_argument_in_complete_inner_call(Script): + param, = Script('def foo(bar): pass\nfoo(foo(bar=1)').goto(2, 8) + assert (param.name, param.line, param.column) == ('bar', 1, 8) + + def test_goto_module(Script): def check(line, expected, follow_imports=False): script = Script(path=path)