From 4e82409cc16bb568f6d2612978dd41d1afa301b0 Mon Sep 17 00:00:00 2001 From: Val Markovic Date: Sat, 27 Feb 2016 16:12:24 -0800 Subject: [PATCH] Futurize pass + manual fixes --- python/ycm/base.py | 17 +++++++-- python/ycm/client/base_request.py | 14 +++++-- python/ycm/client/command_request.py | 8 ++++ .../ycm/client/completer_available_request.py | 8 ++++ python/ycm/client/completion_request.py | 22 +++++++---- python/ycm/client/event_notification.py | 8 ++++ python/ycm/client/omni_completion_request.py | 19 +++++++--- .../ycm/client/tests/command_request_test.py | 12 +++++- .../client/tests/completion_request_test.py | 14 +++++-- python/ycm/client/ycmd_keepalive.py | 8 ++++ python/ycm/diagnostic_interface.py | 23 +++++++---- python/ycm/omni_completer.py | 10 ++++- python/ycm/paths.py | 8 ++++ python/ycm/syntax_parse.py | 11 +++++- python/ycm/test_utils.py | 8 ++++ python/ycm/tests/base_test.py | 8 ++++ python/ycm/tests/event_notification_test.py | 8 ++++ .../tests/omni_completion_request_tests.py | 7 ++++ python/ycm/tests/paths_test.py | 8 ++++ python/ycm/tests/postcomplete_tests.py | 8 ++++ python/ycm/tests/syntax_parse_test.py | 8 ++++ python/ycm/tests/vimsupport_test.py | 38 ++++++++----------- python/ycm/vimsupport.py | 27 ++++++++----- python/ycm/youcompleteme.py | 11 +++++- 24 files changed, 247 insertions(+), 66 deletions(-) diff --git a/python/ycm/base.py b/python/ycm/base.py index e64667d4..b4659bd8 100644 --- a/python/ycm/base.py +++ b/python/ycm/base.py @@ -15,6 +15,15 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 ) } ) diff --git a/python/ycm/client/base_request.py b/python/ycm/client/base_request.py index 83b4159b..c3eb2224 100644 --- a/python/ycm/client/base_request.py +++ b/python/ycm/client/base_request.py @@ -15,8 +15,16 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/client/command_request.py b/python/ycm/client/command_request.py index 8b7c12cb..28dc1278 100644 --- a/python/ycm/client/command_request.py +++ b/python/ycm/client/command_request.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/client/completer_available_request.py b/python/ycm/client/completer_available_request.py index 620edfa0..a90ef1cb 100644 --- a/python/ycm/client/completer_available_request.py +++ b/python/ycm/client/completer_available_request.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 ) diff --git a/python/ycm/client/completion_request.py b/python/ycm/client/completion_request.py index e162b8e5..5b66ef3e 100644 --- a/python/ycm/client/completion_request.py +++ b/python/ycm/client/completion_request.py @@ -15,7 +15,15 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . -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: diff --git a/python/ycm/client/event_notification.py b/python/ycm/client/event_notification.py index 2200fc63..77e05a87 100644 --- a/python/ycm/client/event_notification.py +++ b/python/ycm/client/event_notification.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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, diff --git a/python/ycm/client/omni_completion_request.py b/python/ycm/client/omni_completion_request.py index 48cb112f..2bcb2911 100644 --- a/python/ycm/client/omni_completion_request.py +++ b/python/ycm/client/omni_completion_request.py @@ -15,7 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . -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 diff --git a/python/ycm/client/tests/command_request_test.py b/python/ycm/client/tests/command_request_test.py index d62518ba..40cdaa57 100644 --- a/python/ycm/client/tests/command_request_test.py +++ b/python/ycm/client/tests/command_request_test.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 ): diff --git a/python/ycm/client/tests/completion_request_test.py b/python/ycm/client/tests/completion_request_test.py index c1b19534..d2417b8e 100644 --- a/python/ycm/client/tests/completion_request_test.py +++ b/python/ycm/client/tests/completion_request_test.py @@ -15,13 +15,21 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/client/ycmd_keepalive.py b/python/ycm/client/ycmd_keepalive.py index b9980b53..fca59f42 100644 --- a/python/ycm/client/ycmd_keepalive.py +++ b/python/ycm/client/ycmd_keepalive.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index 03b8de02..6cea2e73 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -15,6 +15,15 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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' ], diff --git a/python/ycm/omni_completer.py b/python/ycm/omni_completer.py index e5a3c76c..e9703311 100644 --- a/python/ycm/omni_completer.py +++ b/python/ycm/omni_completer.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 ) ) diff --git a/python/ycm/paths.py b/python/ycm/paths.py index 9ba85320..e23522a3 100644 --- a/python/ycm/paths.py +++ b/python/ycm/paths.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/syntax_parse.py b/python/ycm/syntax_parse.py index f61b445c..e3299e46 100644 --- a/python/ycm/syntax_parse.py +++ b/python/ycm/syntax_parse.py @@ -15,6 +15,15 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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: diff --git a/python/ycm/test_utils.py b/python/ycm/test_utils.py index 0c60f49c..1bb5cd9c 100644 --- a/python/ycm/test_utils.py +++ b/python/ycm/test_utils.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/tests/base_test.py b/python/ycm/tests/base_test.py index 11e4ae79..26153ccf 100644 --- a/python/ycm/tests/base_test.py +++ b/python/ycm/tests/base_test.py @@ -17,6 +17,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 diff --git a/python/ycm/tests/event_notification_test.py b/python/ycm/tests/event_notification_test.py index 4bfb7895..328c629e 100644 --- a/python/ycm/tests/event_notification_test.py +++ b/python/ycm/tests/event_notification_test.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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() diff --git a/python/ycm/tests/omni_completion_request_tests.py b/python/ycm/tests/omni_completion_request_tests.py index f605db3e..4f7a6822 100644 --- a/python/ycm/tests/omni_completion_request_tests.py +++ b/python/ycm/tests/omni_completion_request_tests.py @@ -15,6 +15,13 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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_ diff --git a/python/ycm/tests/paths_test.py b/python/ycm/tests/paths_test.py index eb1d1ba0..06071a34 100644 --- a/python/ycm/tests/paths_test.py +++ b/python/ycm/tests/paths_test.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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() diff --git a/python/ycm/tests/postcomplete_tests.py b/python/ycm/tests/postcomplete_tests.py index aaf8bc26..6a4b6a9f 100644 --- a/python/ycm/tests/postcomplete_tests.py +++ b/python/ycm/tests/postcomplete_tests.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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() diff --git a/python/ycm/tests/syntax_parse_test.py b/python/ycm/tests/syntax_parse_test.py index 276c6796..d1270677 100644 --- a/python/ycm/tests/syntax_parse_test.py +++ b/python/ycm/tests/syntax_parse_test.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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() diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index 7f8de3c5..2cea87cd 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -15,6 +15,14 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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,27 +1175,13 @@ 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 ): - vimsupport.CloseBuffersForFilename( 'some_filename' ) + new_callable = ExtendedMock ) +def CloseBuffersForFilename_test( vim_command, *args ): + vimsupport.CloseBuffersForFilename( 'some_filename' ) vim_command.assert_has_exact_calls( [ call( 'silent! bwipeout! 2' ), @@ -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 = { diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 0ed090f9..2a3ad5fa 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -15,13 +15,22 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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 :silent! checktime {0}'" .format( filename ) ) - if position is 'end': + if position == 'end': vim.command( 'silent! normal G zz' ) diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index cf3f4f17..dab6ed67 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -15,6 +15,15 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +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