xrange not defined running under Python 3.3

Bug #1272569 reported by Wincent Colaiuta on 2014-01-24
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UltiSnips
Invalid
Undecided
Unassigned

Bug Description

I'm seeing a stack trace like this one trying to open a JS file with Vim 7.4, linked against Python 3.3:

Error detected while processing function UltiSnips_FileTypeChanged:
line 2:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1144, in add_buffer_filetypes
    self._ensure_all_loaded()
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1123, in _ensure_all_loaded
    self._ensure_loaded(ft)
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1115, in _ensure_loaded
    self._load_snippets_for(ft)
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1079, in _load_snippets_for
    for fn in self.base_snippet_files_for(ft):
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1013, in base_snippet_files_for
    if _should_reverse_search_path():
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 59, in _should_reverse_search_path
    return not _snippets_dir_is_before_plugin_dir()
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 46, in _snippets_dir_is_before_plugin_dir
    plugin_path_index = paths.index(_plugin_dir())
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 25, in _plugin_dir
    for i in xrange(10):
NameError: global name 'xrange' is not defined

Output of :py3 import sys; print(sys.version):

3.3.3 (default, Jan 24 2014, 14:40:19)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)]

On actually trying to complete a snippet, like say this one:

snippet log "console.log"
console.log(${1});
endsnippet

I get a much harder to read stack trace like this on typing "log" and hitting <tab>:

Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
Traceback (most recent call last):
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 65, in wrapper
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    return f(self, *args, **kwds)
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 588, in expand
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    if not self._try_expand():
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 967, in _try_expand
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    snippets = self._snips(before, False)
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 880, in _snips
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    self._ensure_all_loaded()
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1123, in _ensure_all_loaded
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    self._ensure_loaded(ft)
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1114, in _ensure_loaded
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    if self._needs_update(ft):
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1097, in _needs_update
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    cur_snips = set(self.base_snippet_files_for(ft))
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 1013, in base_snippet_files_for
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    if _should_reverse_search_path():
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 59, in _should_reverse_search_path
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    return not _snippets_dir_is_before_plugin_dir()
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 46, in _snippets_dir_is_before_plugin_dir
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    plugin_path_index = paths.index(_plugin_dir())
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 25, in _plugin_dir
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    for i in xrange(10):
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
NameError: global name 'xrange' is not defined
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
During handling of the above exception, another exception occurred:
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
Traceback (most recent call last):
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "<string>", line 1, in <module>
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 76, in wrapper
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    _vim.new_scratch_buffer(s)
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/_vim.py", line 119, in new_scratch_buffer
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    command("set ft=text")
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
  File "/home/glh/code/wincent/.vim/bundle/ultisnips/plugin/UltiSnips/_vim.py", line 104, in command
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
    return as_unicode(vim.command(as_vimencoding(s)))
Press ENTER or type command to continue
Error detected while processing function UltiSnips_ExpandSnippet:
line 1:
vim.error: Vim(py3):Traceback (most recent call last):

Wincent Colaiuta (win-wincent) wrote :

I should also add, I added this to my .vimrc:

let g:UltiSnipsUsePythonVersion = 3

but the error remains.

Wincent Colaiuta (win-wincent) wrote :

Whoops. Looks like a load order issue.

g:UltiSnipsUsePythonVersion was getting defined too late in the start-up process, after UltiSnips. I've moved it earlier in the sequence and all is good.

Sorry for the noise.

Changed in ultisnips:
status: New → Invalid
Changed in ultisnips:
status: Invalid → New
Wincent Colaiuta (win-wincent) wrote :

Actually, I take it back. I got confused because I was switching back and forth between two machines.

I am definitely able to reproduce it, even if the `let g:UltiSnips ...` line is the very first line in the .vimrc

Wincent Colaiuta (win-wincent) wrote :

The culprit seems to be a lingering call to xrange in `plugin/UltiSnips/__init__.py`; if I replace that with range, the problem goes away.

I can see now that this is fixed in commit 1545b8327d4c4a9fd90e741568e6323985c698ee, so going to mark as invalid.

Changed in ultisnips:
status: New → Invalid
SirVer (sirver) wrote :

Glad that this got sorted out! I should really release a new version soonish.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers