-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPCompleter doesn't work inside tuples/arrays #14585
Comments
The case of unclosed parenthesis is already handled, but this case is not. Briefly the relevant code is: ipython/IPython/core/completer.py Lines 1144 to 1150 in d7eebae
and then in evaluation we use naive approach of trimming on the left side if there is a syntax error - unless there is not. ipython/IPython/core/completer.py Lines 1221 to 1228 in d7eebae
I think that the problem might be that Partial parsing of Python is not easy in the general case. We could possibly consider some heuristics for closing parenthesis for tuples and lists and after guarded evaluation extract the relevant part. To spell it out we cannot just split on space as in general case it could be |
Some more related cases:
|
I'm wondering, finding completions using jedi is a problem, (if you set |
FWIW we turned off jedi because it had historically been too slow, so using Jedi as a solution is unlikely to be ideal (unless its much faster than it used to be) |
The following is also a fix
|
I think it's computing the completions that is slow with jedi – because of all the inference and need to access libraries code; Jedi (and its dependency, parso), also offer the ability to simply parse incomplete Python code – which should be much faster – I'm suggesting using only the parsing to extract the current expression the cursor is in. @krassowski pointed out that a disadvantage is jedi/parso need a new release on every new Python version because of Python syntax changes so that may be a better reason to not use it. |
I think restoring the previous behaviour by adding back the attempt to evaluate:
prior to:
would be a sensible solution improving the current situation. In the edge cases like |
In progress work toward #14585 guarded eval strip leading characters until it find soemthing, this is problematic as `(1, x`, becomes valid after 1 char strip: `1, x` is a tuple; So now we trim until it is valid an not a tuple. This is still imperfect as things like `(1, a[" "].y` will be trimmed to `y`, while it should stop with `a[" "].y` ? I think maybe we should back-propagate; build back up from `y`, to `a[" "].y`, greedily until we get the last valid expression – skipping any unbalanced parentheses/quotes if we encounter imblanced.
Consider the following snippet -
This doesn't return any autocomplete suggestions. This is fixed by enabling
jedi
but can we look into fixing this for the IPCompleter?This is reproducible on both ipython v8.22.0 and v8.28.0
The text was updated successfully, but these errors were encountered: