Remove Python 2 stuff

This commit is contained in:
Dave Halter
2020-12-27 00:44:17 +01:00
parent 57757bd334
commit 3a1c900a26
5 changed files with 46 additions and 91 deletions

View File

@@ -62,35 +62,13 @@ let s:supports_buffer_usages = has('nvim') || exists('*prop_add')
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
let s:script_path = expand('<sfile>:p:h:h') let s:script_path = expand('<sfile>:p:h:h')
" Initialize Python (PythonJedi command).
function! s:init_python() abort function! s:init_python() abort
" Use g:jedi#force_py_version for loading Jedi, or fall back to using " Use g:jedi#force_py_version for loading Jedi, or fall back to using
" `has()` - preferring Python 3. " `has()` - preferring Python 3.
let loader_version = get(g:, 'jedi#loader_py_version', g:jedi#force_py_version) if !has('python3')
if loader_version ==# 'auto' throw 'jedi-vim requires Vim with support for Python 3.'
if has('python3')
let loader_version = 3
elseif has('python')
let loader_version = 2
else
throw 'jedi-vim requires Vim with support for Python 2 or 3.'
endif
else
if loader_version =~# '^3'
let loader_version = 3
elseif loader_version =~# '^2'
let loader_version = 2
else
if !exists('g:jedi#squelch_py_warning')
echohl WarningMsg
echom printf("jedi-vim: could not determine Python loader version from 'g:jedi#loader_py_version/g:jedi#force_py_version' (%s), using 3.",
\ loader_version)
echohl None
endif
let loader_version = 3
endif
endif endif
call jedi#setup_python_imports(loader_version) call jedi#setup_python_imports()
return 1 return 1
endfunction endfunction
@@ -145,20 +123,7 @@ function! jedi#init_python() abort
endfunction endfunction
let s:python_version = 'null' function! jedi#setup_python_imports() abort
function! jedi#setup_python_imports(py_version) abort
if a:py_version == 2
let cmd_exec = 'python'
let s:python_version = 2
elseif a:py_version == 3
let cmd_exec = 'python3'
let s:python_version = 3
else
throw 'jedi#setup_python_imports: invalid py_version: '.a:py_version
endif
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
let g:_jedi_init_error = 0 let g:_jedi_init_error = 0
let init_lines = [ let init_lines = [
\ 'import vim', \ 'import vim',
@@ -176,7 +141,7 @@ function! jedi#setup_python_imports(py_version) abort
\ 'except Exception as exc:', \ 'except Exception as exc:',
\ ' _jedi_handle_exc(sys.exc_info())', \ ' _jedi_handle_exc(sys.exc_info())',
\ ] \ ]
exe 'PythonJedi exec('''.escape(join(init_lines, '\n'), "'").''')' exe 'python3 exec('''.escape(join(init_lines, '\n'), "'").''')'
if g:_jedi_init_error isnot 0 if g:_jedi_init_error isnot 0
throw printf('jedi#setup_python_imports: %s', g:_jedi_init_error) throw printf('jedi#setup_python_imports: %s', g:_jedi_init_error)
endif endif
@@ -204,25 +169,24 @@ function! jedi#debug_info() abort
echo "\n" echo "\n"
echo '##### Global Python' echo '##### Global Python'
echo "\n" echo "\n"
echo 'Using Python version '.s:python_version.' to access Jedi.' echo 'Using Python version 3 to access Jedi.'
let pyeval = s:python_version == 3 ? 'py3eval' : 'pyeval'
let s:pythonjedi_called = 0 let s:pythonjedi_called = 0
try try
PythonJedi import vim; vim.command('let s:pythonjedi_called = 1') python3 import vim; vim.command('let s:pythonjedi_called = 1')
catch catch
echo 'Error when trying to import vim: '.v:exception echo 'Error when trying to import vim: '.v:exception
endtry endtry
if !s:pythonjedi_called if !s:pythonjedi_called
echohl WarningMsg echohl WarningMsg
echom 'PythonJedi failed to run, likely a Python config issue.' echom 'python3 failed to run, likely a Python config issue.'
if exists(':checkhealth') == 2 if exists(':checkhealth') == 2
echom 'Try :checkhealth for more information.' echom 'Try :checkhealth for more information.'
endif endif
echohl None echohl None
else else
try try
PythonJedi from jedi_vim_debug import display_debug_info python3 from jedi_vim_debug import display_debug_info
PythonJedi display_debug_info() python3 display_debug_info()
catch catch
echohl WarningMsg echohl WarningMsg
echo 'Error when running display_debug_info: '.v:exception echo 'Error when running display_debug_info: '.v:exception
@@ -297,26 +261,26 @@ call jedi#init_python() " Might throw an error.
" functions that call python code " functions that call python code
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
function! jedi#goto() abort function! jedi#goto() abort
PythonJedi jedi_vim.goto(mode="goto") python3 jedi_vim.goto(mode="goto")
endfunction endfunction
function! jedi#goto_assignments() abort function! jedi#goto_assignments() abort
PythonJedi jedi_vim.goto(mode="assignment") python3 jedi_vim.goto(mode="assignment")
endfunction endfunction
function! jedi#goto_definitions() abort function! jedi#goto_definitions() abort
PythonJedi jedi_vim.goto(mode="definition") python3 jedi_vim.goto(mode="definition")
endfunction endfunction
function! jedi#goto_stubs() abort function! jedi#goto_stubs() abort
PythonJedi jedi_vim.goto(mode="stubs") python3 jedi_vim.goto(mode="stubs")
endfunction endfunction
function! jedi#usages() abort function! jedi#usages() abort
if exists('#jedi_usages#BufWinEnter') if exists('#jedi_usages#BufWinEnter')
call jedi#clear_usages() call jedi#clear_usages()
endif endif
PythonJedi jedi_vim.usages() python3 jedi_vim.usages()
endfunction endfunction
if !s:supports_buffer_usages if !s:supports_buffer_usages
@@ -340,7 +304,7 @@ endfunction
" Show usages for current window (Vim without textprops only). " Show usages for current window (Vim without textprops only).
function! jedi#_show_usages_in_win() abort function! jedi#_show_usages_in_win() abort
PythonJedi jedi_vim.highlight_usages_for_vim_win() python3 jedi_vim.highlight_usages_for_vim_win()
if !exists('#jedi_usages#TextChanged#<buffer>') if !exists('#jedi_usages#TextChanged#<buffer>')
augroup jedi_usages augroup jedi_usages
@@ -393,54 +357,54 @@ function! jedi#clear_usages() abort
augroup END augroup END
endif endif
PythonJedi jedi_vim.clear_usages() python3 jedi_vim.clear_usages()
endfunction endfunction
function! jedi#rename(...) abort function! jedi#rename(...) abort
PythonJedi jedi_vim.rename() python3 jedi_vim.rename()
endfunction endfunction
function! jedi#rename_visual(...) abort function! jedi#rename_visual(...) abort
PythonJedi jedi_vim.rename_visual() python3 jedi_vim.rename_visual()
endfunction endfunction
function! jedi#completions(findstart, base) abort function! jedi#completions(findstart, base) abort
PythonJedi jedi_vim.completions() python3 jedi_vim.completions()
endfunction endfunction
function! jedi#enable_speed_debugging() abort function! jedi#enable_speed_debugging() abort
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False) python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
endfunction endfunction
function! jedi#enable_debugging() abort function! jedi#enable_debugging() abort
PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout) python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
endfunction endfunction
function! jedi#disable_debugging() abort function! jedi#disable_debugging() abort
PythonJedi jedi_vim.jedi.set_debug_function(None) python3 jedi_vim.jedi.set_debug_function(None)
endfunction endfunction
function! jedi#py_import(args) abort function! jedi#py_import(args) abort
PythonJedi jedi_vim.py_import() python3 jedi_vim.py_import()
endfun endfun
function! jedi#choose_environment(args) abort function! jedi#choose_environment(args) abort
PythonJedi jedi_vim.choose_environment() python3 jedi_vim.choose_environment()
endfun endfun
function! jedi#load_project(args) abort function! jedi#load_project(args) abort
PythonJedi jedi_vim.load_project() python3 jedi_vim.load_project()
endfun endfun
function! jedi#py_import_completions(argl, cmdl, pos) abort function! jedi#py_import_completions(argl, cmdl, pos) abort
PythonJedi jedi_vim.py_import_completions() python3 jedi_vim.py_import_completions()
endfun endfun
function! jedi#clear_cache(bang) abort function! jedi#clear_cache(bang) abort
if a:bang if a:bang
PythonJedi jedi_vim.jedi.cache.clear_time_caches(True) python3 jedi_vim.jedi.cache.clear_time_caches(True)
else else
PythonJedi jedi_vim.jedi.cache.clear_time_caches(False) python3 jedi_vim.jedi.cache.clear_time_caches(False)
endif endif
endfunction endfunction
@@ -449,7 +413,7 @@ endfunction
" show_documentation " show_documentation
" ------------------------------------------------------------------------ " ------------------------------------------------------------------------
function! jedi#show_documentation() abort function! jedi#show_documentation() abort
PythonJedi if jedi_vim.show_documentation() is None: vim.command('return') python3 if jedi_vim.show_documentation() is None: vim.command('return')
let bn = bufnr('__doc__') let bn = bufnr('__doc__')
if bn > 0 if bn > 0
@@ -532,7 +496,7 @@ endfunction
" Highlight usages for a buffer if not done so yet (Neovim only). " Highlight usages for a buffer if not done so yet (Neovim only).
function! s:usages_for_pending_buffers() abort function! s:usages_for_pending_buffers() abort
PythonJedi jedi_vim._handle_pending_usages_for_buf() python3 jedi_vim._handle_pending_usages_for_buf()
endfunction endfunction
@@ -542,7 +506,7 @@ function! jedi#goto_window_on_enter() abort
if l:data.bufnr if l:data.bufnr
" close goto_window buffer " close goto_window buffer
normal! ZQ normal! ZQ
PythonJedi jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)')) python3 jedi_vim.new_buffer(vim.eval('bufname(l:data.bufnr)'))
call cursor(l:data.lnum, l:data.col) call cursor(l:data.lnum, l:data.col)
else else
echohl WarningMsg | echo 'Builtin module cannot be opened.' | echohl None echohl WarningMsg | echo 'Builtin module cannot be opened.' | echohl None
@@ -604,7 +568,7 @@ function! jedi#show_call_signatures() abort
let s:show_call_signatures_last = [line, col, curline] let s:show_call_signatures_last = [line, col, curline]
if reload_signatures if reload_signatures
PythonJedi jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
endif endif
endfunction endfunction
@@ -615,7 +579,7 @@ function! jedi#clear_call_signatures() abort
endif endif
let s:show_call_signatures_last = [0, 0, ''] let s:show_call_signatures_last = [0, 0, '']
PythonJedi jedi_vim.clear_call_signatures() python3 jedi_vim.clear_call_signatures()
endfunction endfunction
@@ -760,7 +724,7 @@ function! jedi#setup_completion() abort
endif endif
endfunction endfunction
"PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False) "python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
"PythonJedi jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout) "python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
" vim: set et ts=4: " vim: set et ts=4:

View File

@@ -255,7 +255,7 @@ def choose_environment():
vim_command( vim_command(
'setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted readonly nomodifiable') 'setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted readonly nomodifiable')
vim_command('noremap <buffer> <ESC> :bw<CR>') vim_command('noremap <buffer> <ESC> :bw<CR>')
vim_command('noremap <buffer> <CR> :PythonJedi jedi_vim.choose_environment_hit_enter()<CR>') vim_command('noremap <buffer> <CR> :python3 jedi_vim.choose_environment_hit_enter()<CR>')
@catch_and_print_exceptions @catch_and_print_exceptions

View File

@@ -16,14 +16,8 @@ describe 'documentation docstrings'
Expect bufname('%') == "__doc__" Expect bufname('%') == "__doc__"
Expect &filetype == 'rst' Expect &filetype == 'rst'
let header = getline(1, 2) let header = getline(1, 2)
PythonJedi vim.vars["is_py2"] = sys.version_info[0] == 2 Expect header[0] == "Docstring for class builtins.ImportError"
if g:is_py2 Expect header[1] == "========================================"
Expect header[0] == "Docstring for class __builtin__.ImportError"
Expect header[1] == "==========================================="
else
Expect header[0] == "Docstring for class builtins.ImportError"
Expect header[1] == "========================================"
endif
let content = join(getline(3, '$'), "\n") let content = join(getline(3, '$'), "\n")
Expect stridx(content, "Import can't find module") > 0 Expect stridx(content, "Import can't find module") > 0
normal K normal K

View File

@@ -91,7 +91,7 @@ describe 'goto with buffers'
put = ['import os'] put = ['import os']
normal G$ normal G$
call jedi#goto_assignments() call jedi#goto_assignments()
PythonJedi jedi_vim.goto() python3 jedi_vim.goto()
Expect CurrentBufferIsModule('os') == 0 Expect CurrentBufferIsModule('os') == 0
" Without hidden, it's not possible to open a new buffer, when the old " Without hidden, it's not possible to open a new buffer, when the old
" one is not saved. " one is not saved.

View File

@@ -45,9 +45,6 @@ describe 'signatures'
end end
it 'highlights correct argument' it 'highlights correct argument'
if !has('python3')
SKIP 'py2: no signatures with print()'
endif
noautocmd normal o noautocmd normal o
doautocmd CursorHoldI doautocmd CursorHoldI
noautocmd normal iprint(42, sep="X", ) noautocmd normal iprint(42, sep="X", )
@@ -66,7 +63,7 @@ describe 'signatures'
it 'no signature' it 'no signature'
exe 'normal ostr ' exe 'normal ostr '
Python jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
Expect getline(1, '$') == ['', 'str '] Expect getline(1, '$') == ['', 'str ']
end end
@@ -74,7 +71,7 @@ describe 'signatures'
let g:jedi#show_call_signatures = 0 let g:jedi#show_call_signatures = 0
exe 'normal ostr( ' exe 'normal ostr( '
Python jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
Expect getline(1, '$') == ['', 'str( '] Expect getline(1, '$') == ['', 'str( ']
let g:jedi#show_call_signatures = 1 let g:jedi#show_call_signatures = 1
@@ -86,7 +83,7 @@ describe 'signatures'
exe 'normal ostaticmethod( ' exe 'normal ostaticmethod( '
redir => msg redir => msg
Python jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
redir END redir END
Expect msg == "\nstaticmethod(f: Callable[..., Any])" Expect msg == "\nstaticmethod(f: Callable[..., Any])"
@@ -98,7 +95,7 @@ describe 'signatures'
normal Sdef foo(a, b): pass normal Sdef foo(a, b): pass
exe 'normal ofoo(a, b, c, ' exe 'normal ofoo(a, b, c, '
redir => msg redir => msg
Python jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
redir END redir END
Expect msg == "\nfoo(a, b)" Expect msg == "\nfoo(a, b)"
end end
@@ -109,7 +106,7 @@ describe 'signatures'
function! Signature() function! Signature()
redir => msg redir => msg
Python jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
redir END redir END
return msg return msg
endfunction endfunction
@@ -142,7 +139,7 @@ describe 'signatures'
exe 'normal ostr ' exe 'normal ostr '
redir => msg redir => msg
Python jedi_vim.show_call_signatures() python3 jedi_vim.show_call_signatures()
redir END redir END
Expect msg == "\n" Expect msg == "\n"
end end