Skip to content
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

Python 3.12: Syntax warnings for escape sequences #1500

Closed
sanjayankur31 opened this issue Sep 22, 2023 · 5 comments
Closed

Python 3.12: Syntax warnings for escape sequences #1500

sanjayankur31 opened this issue Sep 22, 2023 · 5 comments

Comments

@sanjayankur31
Copy link
Contributor

With Python 3.12, invalid escape sequences throw SyntaxWarnings instead of Deprecation warnings:

A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+.\d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence), use raw strings for regular expression: re.compile(r"\d+.\d+"). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.)

So, I think the regular expressions that we use in our snippets need to either be tweaked, or converted to raw strings which is probably easier. Otherwise, I get such warnings (with YouCompleteMe):

An error occured. This is either a bug in UltiSnips or a bug in a
snippet definition. If you think this is a bug, please report it to
https://github.com/SirVer/ultisnips/issues/new
Please read and follow:
https://github.com/SirVer/ultisnips/blob/master/CONTRIBUTING.md#reproducing-bugs

Following is the full stack trace:
Traceback (most recent call last):
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/err_to_scratch_buffer.py", line 47, in wrapper
    return func(self, *args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 205, in snippets_in_current_scope
    snippets = self._snips(before, True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 679, in _snips
    source.ensure(filetypes)
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet/source/file/base.py", line 32, in ensure
    self._load_snippets_for(ft)
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet/source/file/base.py", line 53, in _load_snippets_for
    for fn in self._get_all_snippet_files_for(ft):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet/source/file/ulti_snips.py", line 218, in _get_all_snippet_files_for
    return find_all_snippet_files(ft)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet/source/file/ulti_snips.py", line 74, in find_all_snippet_files
    for directory in find_all_snippet_directories():
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet/source/file/ulti_snips.py", line 39, in find_all_snippet_directories
    if vim_helper.eval("exists('b:UltiSnipsSnippetDirectories')") == "1":
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asinha/.vim/plugged/ultisnips/pythonx/UltiSnips/vim_helper.py", line 123, in eval
    return vim.eval(text)
           ^^^^^^^^^^^^^^
vim.error: Vim:<global-snippets>:15: SyntaxWarning: invalid escape sequence '\w'

No such warnings are received on Python <= 3.11.

Expected behavior:

No warnings

Actual behavior:

Warnings related to escape sequences.
Steps to reproduce

  1. Use provided vimrc file, install plugins: vim -u <path to vimrc> -c :PlugInstall
  2. Open a new Java file with vim, but using provided vimrc file : vim -u <path to vimrc> test.java
  3. Enter insert mode with i. Type a letter, like p. View error message at bottom, or use :messages.

  • Operating System: : Fedora 39

  • Vim Version: VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 05 2023 00:00:00); Included patches: 1-1872

  • UltiSnips Version: Ultisnips: SirVer/ultisnips@24a3ebb , vim-snippets: ccc2fa1

  • Python inside Vim: 3.12.0rc3 (main, Sep 19 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)]

  • Docker repo/vimrc:

set nocompatible
call plug#begin('~/.vim/plugged')

filetype off
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'

call plug#end()
@zhuzhzh
Copy link
Contributor

zhuzhzh commented Nov 27, 2023

I hit the same issue.

@lpil
Copy link
Contributor

lpil commented Nov 27, 2023

Thanks for the fix. Please update to the latest version

@lpil lpil closed this as completed Nov 27, 2023
@sanjayankur31
Copy link
Contributor Author

Sorry @lpil : I didn't provide a fix for this one (it'll probably require a complete review of the Ultisnips snippets).

@lpil lpil reopened this Nov 27, 2023
@zhuzhzh
Copy link
Contributor

zhuzhzh commented Nov 28, 2023

I create one pr to fix this issue @ https://github.com/zhuzhzh/vim-snippets

@lpil
Copy link
Contributor

lpil commented Nov 29, 2023

Thank you

@lpil lpil closed this as completed Nov 29, 2023
sionleroux added a commit to sionleroux/vimrc that referenced this issue Sep 6, 2024
Critically, the update to the honza/vim-snippets repo fixes a character
encoding issue that was constantly spamming while using snippets.
Luckily I found the issue on GitHub, it's pretty recent[1], otherwise I
was gearing up to switch to neosnippets, nothing wrong with it, it might
even be better, cool, modern async stuff, but it's not what's in my
muscle memory.

[1]: honza/vim-snippets#1500
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

No branches or pull requests

3 participants