SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.55k stars 691 forks source link

Python 3.12: Syntax warnings for escape sequences #1540

Closed sanjayankur31 closed 1 year ago

sanjayankur31 commented 1 year ago

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.

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

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

call plug#end()
SirVer commented 1 year ago

UltiSnips is not shipping with snippets, so this bug is either in your private snippets or in honza/vim-snippets to be addressed.

sanjayankur31 commented 1 year ago

Cool, migrated: https://github.com/honza/vim-snippets/issues/1500