Futurize pass + manual fixes

This commit is contained in:
Val Markovic 2016-02-27 16:12:24 -08:00
parent cb8607796e
commit 4e82409cc1
24 changed files with 247 additions and 66 deletions

View File

@ -15,6 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from future.utils import iteritems
from ycm import vimsupport
from ycmd import user_options_store
from ycmd import request_wrap
@ -29,7 +38,7 @@ def BuildServerConf():
vim_globals = vimsupport.GetReadOnlyVimGlobals( force_python_objects = True )
server_conf = {}
for key, value in vim_globals.items():
for key, value in iteritems( vim_globals ):
if not key.startswith( YCM_VAR_PREFIX ):
continue
try:
@ -45,7 +54,7 @@ def BuildServerConf():
def LoadJsonDefaultsIntoVim():
defaults = user_options_store.DefaultOptions()
vim_defaults = {}
for key, value in defaults.iteritems():
for key, value in iteritems( defaults ):
vim_defaults[ 'ycm_' + key ] = value
vimsupport.LoadDictIntoVimGlobals( vim_defaults, overwrite = False )
@ -115,7 +124,7 @@ def AdjustCandidateInsertionText( candidates ):
new_candidates = []
for candidate in candidates:
if type( candidate ) is dict:
if isinstance( candidate, dict ):
new_candidate = candidate.copy()
if not 'abbr' in new_candidate:
@ -127,7 +136,7 @@ def AdjustCandidateInsertionText( candidates ):
new_candidates.append( new_candidate )
elif type( candidate ) is str:
elif isinstance( candidate, str ) or isinstance( candidate, bytes ):
new_candidates.append(
{ 'abbr': candidate,
'word': NewCandidateInsertionText( candidate, text_after_cursor ) } )

View File

@ -15,8 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
import requests
import urlparse
import urllib.parse
import json
from base64 import b64decode, b64encode
from retries import retries
@ -133,7 +141,7 @@ class BaseRequest( object ):
headers = dict( _HEADERS )
headers[ _HMAC_HEADER ] = b64encode(
CreateRequestHmac( method,
urlparse.urlparse( request_uri ).path,
urllib.parse.urlparse( request_uri ).path,
request_body,
BaseRequest.hmac_secret ) )
return headers
@ -196,7 +204,7 @@ def _ValidateResponseObject( response ):
def _BuildUri( handler ):
return urlparse.urljoin( BaseRequest.server_location, handler )
return urllib.parse.urljoin( BaseRequest.server_location, handler )
SERVER_HEALTHY = False

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
import vim
from ycm.client.base_request import BaseRequest, BuildRequestData, ServerError
from ycm import vimsupport

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
HandleServerException )

View File

@ -15,7 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycmd.utils import ToBytes, ToUnicode
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycmd.utils import ToUnicode
from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
HandleServerException,
MakeServerException )
@ -69,22 +77,22 @@ def ConvertCompletionDataToVimData( completion_data ):
if ( 'extra_data' in completion_data and
'doc_string' in completion_data[ 'extra_data' ] ):
doc_string = ToBytes( completion_data[ 'extra_data' ][ 'doc_string' ] )
doc_string = completion_data[ 'extra_data' ][ 'doc_string' ]
else:
doc_string = ""
if 'insertion_text' in completion_data:
vim_data[ 'word' ] = ToBytes( completion_data[ 'insertion_text' ] )
vim_data[ 'word' ] = completion_data[ 'insertion_text' ]
if 'menu_text' in completion_data:
vim_data[ 'abbr' ] = ToBytes( completion_data[ 'menu_text' ] )
vim_data[ 'abbr' ] = completion_data[ 'menu_text' ]
if 'extra_menu_info' in completion_data:
vim_data[ 'menu' ] = ToBytes( completion_data[ 'extra_menu_info' ] )
vim_data[ 'menu' ] = completion_data[ 'extra_menu_info' ]
if 'kind' in completion_data:
kind = ToUnicode( completion_data[ 'kind' ] )
if kind:
vim_data[ 'kind' ] = ToBytes( kind[ 0 ].lower() )
vim_data[ 'kind' ] = kind[ 0 ].lower()
if 'detailed_info' in completion_data:
vim_data[ 'info' ] = ToBytes( completion_data[ 'detailed_info' ] )
vim_data[ 'info' ] = completion_data[ 'detailed_info' ]
if doc_string:
vim_data[ 'info' ] += '\n' + doc_string
elif doc_string:

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm import vimsupport
from ycmd.responses import UnknownExtraConf
from ycm.client.base_request import ( BaseRequest, BuildRequestData,

View File

@ -15,7 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycmd.utils import ToBytes
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.client.completion_request import CompletionRequest
@ -46,15 +53,15 @@ def ConvertVimDataToCompletionData( vim_data ):
completion_data = {}
if 'word' in vim_data:
completion_data[ 'insertion_text' ] = ToBytes( vim_data[ 'word' ] )
completion_data[ 'insertion_text' ] = vim_data[ 'word' ]
if 'abbr' in vim_data:
completion_data[ 'menu_text' ] = ToBytes( vim_data[ 'abbr' ] )
completion_data[ 'menu_text' ] = vim_data[ 'abbr' ]
if 'menu' in vim_data:
completion_data[ 'extra_menu_info' ] = ToBytes( vim_data[ 'menu' ] )
completion_data[ 'extra_menu_info' ] = vim_data[ 'menu' ]
if 'kind' in vim_data:
completion_data[ 'kind' ] = [ ToBytes( vim_data[ 'kind' ] ) ]
completion_data[ 'kind' ] = [ vim_data[ 'kind' ] ]
if 'info' in vim_data:
completion_data[ 'detailed_info' ] = ToBytes( vim_data[ 'info' ] )
completion_data[ 'detailed_info' ] = vim_data[ 'info' ]
return completion_data

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()
@ -24,7 +32,7 @@ from nose.tools import ok_
from ycm.client.command_request import CommandRequest
class GoToResponse_QuickFix_test:
class GoToResponse_QuickFix_test( object ):
"""This class tests the generation of QuickFix lists for GoTo responses which
return multiple locations, such as the Python completer and JavaScript
completer. It mostly proves that we use 1-based indexing for the column
@ -92,7 +100,7 @@ class GoToResponse_QuickFix_test:
] )
class Response_Detection_test:
class Response_Detection_test( object ):
def BasicResponse_test( self ):
def _BasicResponseTest( command, response ):

View File

@ -15,13 +15,21 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from nose.tools import eq_
from ycm.test_utils import MockVimModule
vim_mock = MockVimModule()
from .. import completion_request
class ConvertCompletionResponseToVimDatas_test:
class ConvertCompletionResponseToVimDatas_test( object ):
""" This class tests the
completion_request._ConvertCompletionResponseToVimDatas method """
@ -32,10 +40,10 @@ class ConvertCompletionResponseToVimDatas_test:
try:
eq_( expected_vim_data, vim_data )
except:
print "Expected:\n'{0}'\nwhen parsing:\n'{1}'\nBut found:\n'{2}'".format(
print( "Expected:\n'{0}'\nwhen parsing:\n'{1}'\nBut found:\n'{2}'".format(
expected_vim_data,
completion_data,
vim_data )
vim_data ) )
raise

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
import time
from threading import Thread
from ycm.client.base_request import BaseRequest

View File

@ -15,6 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from future.utils import itervalues, iteritems
from collections import defaultdict, namedtuple
from ycm import vimsupport
import vim
@ -95,8 +104,8 @@ class DiagnosticInterface( object ):
line_to_diags = self._buffer_number_to_line_to_diags[
vim.current.buffer.number ]
for diags in line_to_diags.itervalues():
matched_diags.extend( filter( predicate, diags ) )
for diags in itervalues( line_to_diags ):
matched_diags.extend( list( filter( predicate, diags ) ) )
return matched_diags
@ -104,7 +113,7 @@ def _UpdateSquiggles( buffer_number_to_line_to_diags ):
vimsupport.ClearYcmSyntaxMatches()
line_to_diags = buffer_number_to_line_to_diags[ vim.current.buffer.number ]
for diags in line_to_diags.itervalues():
for diags in itervalues( line_to_diags ):
for diag in diags:
location_extent = diag[ 'location_extent' ]
is_error = _DiagnosticIsError( diag )
@ -168,11 +177,11 @@ def _GetKeptAndNewSigns( placed_signs, buffer_number_to_line_to_diags,
next_sign_id ):
new_signs = []
kept_signs = []
for buffer_number, line_to_diags in buffer_number_to_line_to_diags.iteritems():
for buffer_number, line_to_diags in iteritems( buffer_number_to_line_to_diags ):
if not vimsupport.BufferIsVisible( buffer_number ):
continue
for line, diags in line_to_diags.iteritems():
for line, diags in iteritems( line_to_diags ):
for diag in diags:
sign = _DiagSignPlacement( next_sign_id,
line,
@ -217,8 +226,8 @@ def _ConvertDiagListToDict( diag_list ):
line_number = location[ 'line_num' ]
buffer_to_line_to_diags[ buffer_number ][ line_number ].append( diag )
for line_to_diags in buffer_to_line_to_diags.itervalues():
for diags in line_to_diags.itervalues():
for line_to_diags in itervalues( buffer_to_line_to_diags ):
for diags in itervalues( line_to_diags ):
# We also want errors to be listed before warnings so that errors aren't
# hidden by the warnings; Vim won't place a sign oven an existing one.
diags.sort( key = lambda diag: ( diag[ 'location' ][ 'column_num' ],

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
import vim
from ycm import vimsupport
from ycmd.completers.completer import Completer
@ -84,7 +92,7 @@ class OmniCompleter( Completer ):
if not hasattr( items, '__iter__' ):
raise TypeError( OMNIFUNC_NOT_LIST )
return filter( bool, items )
return list( filter( bool, items ) )
except ( TypeError, ValueError, vim.error ) as error:
vimsupport.PostVimMessage(
OMNIFUNC_RETURNED_BAD_VALUE + ' ' + str( error ) )

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
import os
import sys
import vim

View File

@ -15,6 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from future.utils import itervalues
import re
import vim
from ycm import vimsupport
@ -174,7 +183,7 @@ def _ConnectGroupChildren( group_name_to_group ):
parent_names.append( line[ len( links_to ): ] )
return parent_names
for group in group_name_to_group.itervalues():
for group in itervalues( group_name_to_group ):
parent_names = GetParentNames( group )
for parent_name in parent_names:

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from mock import MagicMock
from hamcrest import assert_that, equal_to
import re

View File

@ -17,6 +17,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
import contextlib
from nose.tools import eq_, ok_
from mock import patch

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule, ExtendedMock
MockVimModule()

View File

@ -15,6 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from mock import MagicMock
from nose.tools import eq_

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()

View File

@ -15,6 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import ExtendedMock, MockVimModule, MockVimCommand
MockVimModule()
@ -565,7 +573,7 @@ def ReplaceChunksInBuffer_UnsortedChunks_test():
eq_( expected_buffer, result_buffer )
class MockBuffer( ):
class MockBuffer( object ):
"""An object that looks like a vim.buffer object, enough for ReplaceChunk to
generate a location list"""
@ -1167,26 +1175,12 @@ def BufferIsVisibleForFilename_test():
eq_( vimsupport.BufferIsVisibleForFilename( 'another_filename' ), False )
@patch( 'ycm.vimsupport.GetBufferNumberForFilename',
side_effect = [ 2, 5, -1 ] )
@patch( 'vim.command',
side_effect = MockVimCommand,
new_callable=ExtendedMock )
def CloseBuffersForFilename_test( vim_command ):
buffers = [
{
'number': 2,
'filename': os.path.realpath( 'some_filename' ),
},
{
'number': 5,
'filename': os.path.realpath( 'some_filename' ),
},
{
'number': 1,
'filename': os.path.realpath( 'another_filename' )
}
]
with patch( 'vim.buffers', buffers ):
new_callable = ExtendedMock )
def CloseBuffersForFilename_test( vim_command, *args ):
vimsupport.CloseBuffersForFilename( 'some_filename' )
vim_command.assert_has_exact_calls( [
@ -1195,8 +1189,8 @@ def CloseBuffersForFilename_test( vim_command ):
], any_order = True )
@patch( 'vim.command', new_callable=ExtendedMock )
@patch( 'vim.current', new_callable=ExtendedMock )
@patch( 'vim.command', new_callable = ExtendedMock )
@patch( 'vim.current', new_callable = ExtendedMock )
def OpenFilename_test( vim_current, vim_command ):
# Options used to open a logfile
options = {

View File

@ -15,13 +15,22 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from future.utils import iterkeys
import vim
import os
import tempfile
import json
import re
from collections import defaultdict
from ycmd.utils import ToBytes, ToUnicode
from ycmd.utils import ToUnicode
from ycmd import user_options_store
BUFFER_COMMAND_MAP = { 'same-buffer' : 'edit',
@ -277,7 +286,7 @@ def ConvertDiagnosticsToQfList( diagnostics ):
'bufnr' : GetBufferNumberForFilename( location[ 'filepath' ] ),
'lnum' : line_num,
'col' : location[ 'column_num' ],
'text' : ToBytes( text ),
'text' : text,
'type' : diagnostic[ 'kind' ][ 0 ],
'valid' : 1
}
@ -310,7 +319,7 @@ def GetReadOnlyVimGlobals( force_python_objects = False ):
def VimExpressionToPythonType( vim_expression ):
result = vim.eval( vim_expression )
if not isinstance( result, basestring ):
if not isinstance( result, str ):
return result
try:
return int( result )
@ -607,7 +616,7 @@ def ReplaceChunks( chunks ):
chunks_by_file = _SortChunksByFile( chunks )
# We sort the file list simply to enable repeatable testing
sorted_file_list = sorted( chunks_by_file.iterkeys() )
sorted_file_list = sorted( iterkeys( chunks_by_file ) )
# Make sure the user is prepared to have her screen mutilated by the new
# buffers
@ -885,7 +894,7 @@ def OpenFilename( filename, options = {} ):
# There is no command in Vim to return to the previous tab so we need to
# remember the current tab if needed.
if not focus and command is 'tabedit':
if not focus and command == 'tabedit':
previous_tab = GetIntValue( 'tabpagenr()' )
else:
previous_tab = None
@ -920,7 +929,7 @@ def OpenFilename( filename, options = {} ):
# focus back (if the focus option is disabled) when opening a new tab or
# window.
if not focus:
if command is 'tabedit':
if command == 'tabedit':
JumpToTab( previous_tab )
if command in [ 'split', 'vsplit' ]:
JumpToPreviousWindow()
@ -930,9 +939,9 @@ def _SetUpLoadedBuffer( command, filename, fix, position, watch ):
"""After opening a buffer, configure it according to the supplied options,
which are as defined by the OpenFilename method."""
if command is 'split':
if command == 'split':
vim.current.window.options[ 'winfixheight' ] = fix
if command is 'vsplit':
if command == 'vsplit':
vim.current.window.options[ 'winfixwidth' ] = fix
if watch:
@ -940,6 +949,6 @@ def _SetUpLoadedBuffer( command, filename, fix, position, watch ):
vim.command( "exec 'au BufEnter <buffer> :silent! checktime {0}'"
.format( filename ) )
if position is 'end':
if position == 'end':
vim.command( 'silent! normal G zz' )

View File

@ -15,6 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from future.utils import iteritems
import os
import vim
import tempfile
@ -303,7 +312,7 @@ class YouCompleteMe( object ):
def GetCompleteDoneHooks( self ):
filetypes = vimsupport.CurrentFiletypes()
for key, value in self._complete_done_hooks.iteritems():
for key, value in iteritems( self._complete_done_hooks ):
if key in filetypes:
yield value