ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.59k stars 233 forks source link

merlin.py: fix python-3.12 Syntax warnings #1798

Closed paparodeo closed 4 months ago

paparodeo commented 4 months ago

The python code for the vim plugin contains the strings "\%" and "\|" which generate SyntaxWarnings on python-3.12. Change the strings to "\\%" and "\\|" which produce the same output and silence the warning.

python 3.12.4 (main, Jun  6 2024, 18:26:44) [GCC 13.3.0] on linux
>>> print("\%\\%")
<stdin>:1: SyntaxWarning: invalid escape sequence '\%'
\%\%
>>> print("\|\\|")
<stdin>:1: SyntaxWarning: invalid escape sequence '\|'
\|\|
paparodeo commented 4 months ago

FYI: this was the vim / python output before this PR

Error detected while processing BufRead Autocommands for "*.ml"..FileType Autocommands for "*"..function <SNR>12_LoadFTPlugin[18]..script vim/merlin/ftplugin/ocaml.vim[2]..vim/merlin/autoload/merlin.vim:
line   86:
vim/merlin/autoload/merlin.py:826: SyntaxWarning: invalid escape sequence '\%'
  startl = "\%{0}l".format(start['line'])
vim/merlin/autoload/merlin.py:828: SyntaxWarning: invalid escape sequence '\%'
  startc = "\%{0}c".format(start['col'] + 1)
vim/merlin/autoload/merlin.py:829: SyntaxWarning: invalid escape sequence '\%'
  return '{0}{1}.*\%{2}l\%{3}c'.format(startl, startc, stop['line'], stop['col'] + 1)
vim/merlin/autoload/merlin.py:835: SyntaxWarning: invalid escape sequence '\%'
  startl = "\%>{0}l".format(start['line'] - 1)
vim/merlin/autoload/merlin.py:837: SyntaxWarning: invalid escape sequence '\%'
  startc = "\%>{0}c".format(start['col'])
vim/merlin/autoload/merlin.py:838: SyntaxWarning: invalid escape sequence '\%'
  return '{0}{1}\%<{2}l\%<{3}c'.format(startl, startc, stop['line'] + 1, stop['col'] + 1)
vim/merlin/autoload/merlin.py:850: SyntaxWarning: invalid escape sequence '\|'
  return "{0}\|{1}\|{2}".format(first_line, middle, last_line)
voodoos commented 4 months ago

Could you add a changelog entry ?

paparodeo commented 4 months ago

Thanks for your contribution @paparodeo, the change looks sound to me and I think should not impact users off python 2 ?

python 2 looks good. same output with one '\' or two '\\'

Python 2.7.18 (default, Jan 31 2024, 16:23:13) 
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("\%\\%")
\%\%
>>> print ("\|\\|")
\|\|