-
-
Notifications
You must be signed in to change notification settings - Fork 42
Handle async do_complete in the debugger #520
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
Conversation
|
This is more to start a discussion than a "this must be merged". It's mostly to start some discussion also with upstream as we sort of disagree that having |
2f295cd to
889df33
Compare
A number of methods of ipykernel can optinally return `awaitable[T]` instead of just `T`, this is the case for `do_complete`. I think it's a mistake ; see ipython/ipykernel#1295 ; in particular because it's easy to forget / hard to properly type-check, and I'd like to make it mandatory in the long term to have await. Spyder seem to not handle the case where do_completer return an awaitable (or more partiularly is `do_complete` is a coroutine function. This tries to handle it – and as of course `do_completer` _can_ be async, all caller _must_ be async. So I try to do all the required updates. Note: I also add explict imports in some test, to get better error message in case those deps are not installed.
889df33 to
2e19c2c
Compare
|
Rebased. I think we agree upstream that things should mostly be async when possible. so +1 to merge this once tests are passing, and you agree., |
ccordoba12
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Carreau! A couple of small questions, the rest looks good to me.
| This is a regression test for issue spyder-ide/spyder#19516 | ||
| """ | ||
| import django |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary now? It wasn't before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not remember.
I would say better error messages in pytest short summary:
- FAILED spyder_kernels/...::test_save_load_hdf5_files - assert '(None, "No m...ed \'h5py\'")' == "({'a': array...(4.5)}, None)"
+ FAILED spyder_kernels/...::test_save_load_hdf5_files - ModuleNotFoundError: No module named 'h5py'and
- FAILED spyder_kernels/...::test_django_settings - assert "'settings':" in '{}'
+ FAILED spyder_kernels/...::test_django_settings - ModuleNotFoundError: No module named 'django'There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the clarification. Merging then.
ccordoba12
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Carreau!
|
@Carreau, I tested this in Spyder and it actually breaks code completions for our debugger. You started this PR by saying:
But that's not actually the case in IPykernel's main nor in the So, I guess these changes are unnecessary and need to be reverted, right? |
The code that call do_complete (and similar) accept both T|awaitable[T] and emit a warning that returning awaitable[T] might become mandatory in the future. Some subclass of ipykernel (I don't remember which) use I haven't changed the base methods because it would break downstream (like Spyder kernel): ipython/ipykernel#1339. This PR ensure that Spyder kernel is not broken when we change the base methods, but we need a release cycle for that. Is there any chances you run with warnings turned into errors and this breaks the completions ? But if you want to revert, feel free to do so. |
Ok, but the thing is through this call:
we're calling IPykernel's spyder-kernels/spyder_kernels/console/kernel.py Lines 451 to 453 in 2e19c2c
And since it's not async today, we're getting this error: [SpyderKernelApp] ERROR | Exception in control handler:
Traceback (most recent call last):
File "/home/carlos/miniconda3/envs/py310-pip/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 362, in process_control
await result
File "/home/carlos/miniconda3/envs/py310-pip/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 831, in complete_request
matches = await matches
File "/home/carlos/Projects/spyder/spyder/external-deps/spyder-kernels/spyder_kernels/customize/spyderpdb.py", line 359, in do_complete
return await self._complete_exclamation(code, cursor_pos)
File "/home/carlos/Projects/spyder/spyder/external-deps/spyder-kernels/spyder_kernels/customize/spyderpdb.py", line 532, in _complete_exclamation
result = await self.shell.kernel._do_complete(code, cursor_pos)
TypeError: object dict can't be used in 'await' expressionWhen googling for it, I found that Or do you know another way in which we could solve this? |
|
Ah, then you need to do like in this PR: this will handle both awaitable and non awaitable. This will work for both an async def function, or a sync function returning a future. |
|
#534 should help, I haven't tried. |
|
Thanks @Carreau! That fixes completions in our debugger with some minor tweaks. |
A number of methods of ipykernel can optionally return
awaitable[T]instead of justT, this is the case fordo_complete.I think it's a mistake ; see ipython/ipykernel#1295 ; in particular because it's easy to forget / hard to properly type-check, and I'd like to make it mandatory in the long term to have await.
Spyder seem to not handle the case where do_completer return an awaitable (or more partiularly is
do_completeis a coroutine function.This tries to handle it – and as of course
do_completercan be async, all caller must be async. So I try to do all the required updates.Note: I also add explict imports in some test, to get better error message in case those deps are not installed.