Send escape sequence SyntaxWarning to logs#2953
Conversation
|
I just tried the branch on windows, and it does appear to fix #2615 ! |
This is indeed coming from Python 3.12, but something is trying to run or analyze the code, resulting in the warning being emitted. My guess is that it's the LSP, since that's the only thing that runs code when a user changes the contents of a document. I suspect that the line of code that's triggering this warning would also trigger other warnings in the console. If we can find that line, we can catch and reroute all warnings to logs and avoid further work down the line. |
|
Ahh-- searching around I do see that jedi-language-server is compiling on diagnostics; I'll add a context manager to silence |
|
|
||
| # send to logs if warning is coming from Positron files | ||
| # also send warnings from attempted compiles from IPython to logs | ||
| # https://github.com/ipython/ipython/blob/8.24.0/IPython/core/async_helpers.py#L151 |
There was a problem hiding this comment.
fixes a bug where executed lines with SyntaxWarnings will return multiple times, since you would get the warning from 1) IPython's attempted compile and 2) actual runtime
seeM
left a comment
There was a problem hiding this comment.
Looks good! Might be worth catching all warnings so we don't need to update this again if another leaks through
| try: | ||
| diagnostic = jedi_utils.lsp_python_diagnostic(uri, doc.source) | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", SyntaxWarning) |
There was a problem hiding this comment.
Rather than ignore SyntaxWarnings, can we redirect all warnings to logger.warning?
|
|
||
| # send to logs if warning is coming from Positron files | ||
| # also send warnings from attempted compiles from IPython to logs | ||
| # https://github.com/ipython/ipython/blob/8.24.0/IPython/core/async_helpers.py#L151 |
Intent
addresses #2615 by sending SyntaxWarnings about escape sequences, that can be populated at compile time, to logs
Approach
Builds on infrastructure set up in #2776
QA Notes
I've been testing with
since the example from #2615 is not reproducible for me.