diff --git a/python/ycm/base.py b/python/ycm/base.py index b4659bd8..238d23ca 100644 --- a/python/ycm/base.py +++ b/python/ycm/base.py @@ -127,7 +127,7 @@ def AdjustCandidateInsertionText( candidates ): if isinstance( candidate, dict ): new_candidate = candidate.copy() - if not 'abbr' in new_candidate: + if 'abbr' not in new_candidate: new_candidate[ 'abbr' ] = new_candidate[ 'word' ] new_candidate[ 'word' ] = NewCandidateInsertionText( diff --git a/python/ycm/client/base_request.py b/python/ycm/client/base_request.py index c5742771..ffc3fac3 100644 --- a/python/ycm/client/base_request.py +++ b/python/ycm/client/base_request.py @@ -44,6 +44,7 @@ _HMAC_HEADER = 'x-ycm-hmac' class BaseRequest( object ): + def __init__( self ): pass @@ -212,6 +213,7 @@ def _BuildUri( handler ): SERVER_HEALTHY = False + def _CheckServerIsHealthyWithCache(): global SERVER_HEALTHY diff --git a/python/ycm/client/completer_available_request.py b/python/ycm/client/completer_available_request.py index 48fdf858..3a480cac 100644 --- a/python/ycm/client/completer_available_request.py +++ b/python/ycm/client/completer_available_request.py @@ -29,6 +29,7 @@ from ycm.client.base_request import ( BaseRequest, BuildRequestData, HandleServerException ) from ycmd.responses import ServerError + class CompleterAvailableRequest( BaseRequest ): def __init__( self, filetypes ): super( CompleterAvailableRequest, self ).__init__() diff --git a/python/ycm/client/tests/completion_request_test.py b/python/ycm/client/tests/completion_request_test.py index d2417b8e..acf02521 100644 --- a/python/ycm/client/tests/completion_request_test.py +++ b/python/ycm/client/tests/completion_request_test.py @@ -29,6 +29,7 @@ vim_mock = MockVimModule() from .. import completion_request + class ConvertCompletionResponseToVimDatas_test( object ): """ This class tests the completion_request._ConvertCompletionResponseToVimDatas method """ diff --git a/python/ycm/diagnostic_interface.py b/python/ycm/diagnostic_interface.py index 6cea2e73..7f7de530 100644 --- a/python/ycm/diagnostic_interface.py +++ b/python/ycm/diagnostic_interface.py @@ -177,7 +177,8 @@ def _GetKeptAndNewSigns( placed_signs, buffer_number_to_line_to_diags, next_sign_id ): new_signs = [] kept_signs = [] - for buffer_number, line_to_diags in iteritems( buffer_number_to_line_to_diags ): + for buffer_number, line_to_diags in iteritems( + buffer_number_to_line_to_diags ): if not vimsupport.BufferIsVisible( buffer_number ): continue @@ -253,8 +254,9 @@ def _NormalizeDiagnostic( diag ): return diag -class _DiagSignPlacement( namedtuple( "_DiagSignPlacement", - [ 'id', 'line', 'buffer', 'is_error' ] ) ): +class _DiagSignPlacement( + namedtuple( "_DiagSignPlacement", + [ 'id', 'line', 'buffer', 'is_error' ] ) ): # We want two signs that have different ids but the same location to compare # equal. ID doesn't matter. def __eq__( self, other ): diff --git a/python/ycm/omni_completer.py b/python/ycm/omni_completer.py index 38da2ede..7e3b77db 100644 --- a/python/ycm/omni_completer.py +++ b/python/ycm/omni_completer.py @@ -33,6 +33,7 @@ OMNIFUNC_RETURNED_BAD_VALUE = 'Omnifunc returned bad value to YCM!' OMNIFUNC_NOT_LIST = ( 'Omnifunc did not return a list or a dict with a "words" ' ' list when expected.' ) + class OmniCompleter( Completer ): def __init__( self, user_options ): super( OmniCompleter, self ).__init__( user_options ) diff --git a/python/ycm/syntax_parse.py b/python/ycm/syntax_parse.py index e3299e46..a4dc7441 100644 --- a/python/ycm/syntax_parse.py +++ b/python/ycm/syntax_parse.py @@ -222,5 +222,3 @@ def _ExtractKeywordsFromGroup( group ): word = word[ :-1 ] keywords.append( word ) return keywords - - diff --git a/python/ycm/tests/__init__.py b/python/ycm/tests/__init__.py index 8b137891..e69de29b 100644 --- a/python/ycm/tests/__init__.py +++ b/python/ycm/tests/__init__.py @@ -1 +0,0 @@ - diff --git a/python/ycm/tests/base_test.py b/python/ycm/tests/base_test.py index 26153ccf..9d1ba270 100644 --- a/python/ycm/tests/base_test.py +++ b/python/ycm/tests/base_test.py @@ -107,8 +107,7 @@ def AdjustCandidateInsertionText_MultipleStrings_test(): eq_( [ { 'abbr': 'foobar', 'word': 'foo' }, { 'abbr': 'zobar', 'word': 'zo' }, { 'abbr': 'qbar', 'word': 'q' }, - { 'abbr': 'bar', 'word': '' }, - ], + { 'abbr': 'bar', 'word': '' }, ], base.AdjustCandidateInsertionText( [ 'foobar', 'zobar', 'qbar', @@ -269,4 +268,3 @@ def CurrentIdentifierFinished_WhitespaceOnly_test(): with MockCurrentColumnAndLineContents( 3, '\t\t\t\t' ): ok_( base.CurrentIdentifierFinished() ) - diff --git a/python/ycm/tests/event_notification_test.py b/python/ycm/tests/event_notification_test.py index 52ca0bac..046cae2a 100644 --- a/python/ycm/tests/event_notification_test.py +++ b/python/ycm/tests/event_notification_test.py @@ -417,4 +417,3 @@ class EventNotification_test( object ): ] ) eq_( self.server_state.GetErrorCount(), 0 ) eq_( self.server_state.GetWarningCount(), 0 ) - diff --git a/python/ycm/tests/omni_completion_request_tests.py b/python/ycm/tests/omni_completion_request_tests.py index 4f7a6822..02fb2e93 100644 --- a/python/ycm/tests/omni_completion_request_tests.py +++ b/python/ycm/tests/omni_completion_request_tests.py @@ -37,7 +37,7 @@ def BuildOmnicompletionRequest( results ): request = OmniCompletionRequest( omni_completer, None ) request.Start() - return request; + return request def Done_AlwaysTrue_test(): diff --git a/python/ycm/tests/postcomplete_tests.py b/python/ycm/tests/postcomplete_tests.py index b61e0b4e..88eab2fe 100644 --- a/python/ycm/tests/postcomplete_tests.py +++ b/python/ycm/tests/postcomplete_tests.py @@ -199,18 +199,19 @@ class PostComplete_test(): @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Te" ) - def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa self, *args ): completions = [ BuildCompletion( "Test" ) ] - result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) + result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( + completions ) eq_( result, True ) @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" ) - def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa self, *args ): completions = [ BuildCompletion( "AAA" ) ] @@ -219,22 +220,24 @@ class PostComplete_test(): @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" ) - def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa self, *args ): completions = [ BuildCompletion( "Test" ) ] - result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) + result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( + completions ) eq_( result, False ) @patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" ) - def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa self, *args ): completions = [ BuildCompletion( "A" ) ] - result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) + result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( + completions ) eq_( result, False ) @@ -243,11 +246,12 @@ class PostComplete_test(): @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( "Te") ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" ) - def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa self, *args ): completions = [ BuildCompletion( "Test" ) ] - result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) + result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( + completions ) eq_( result, True ) @@ -256,7 +260,7 @@ class PostComplete_test(): @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( "X") ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" ) - def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa self, *args ): completions = [ BuildCompletion( "AAA" ) ] @@ -267,11 +271,12 @@ class PostComplete_test(): @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( "Test" ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) - def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa self, *args ): completions = [ BuildCompletion( "Test" ) ] - result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) + result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( + completions ) eq_( result, False ) @@ -280,11 +285,12 @@ class PostComplete_test(): @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( " Quote" ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) - def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( + def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa self, *args ): completions = [ BuildCompletion( "A" ) ] - result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) + result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( + completions ) eq_( result, False ) @@ -309,7 +315,7 @@ class PostComplete_test(): eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() ) - def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( + def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa self ): completions = [ BuildCompletion( None ) ] with self._SetupForCsharpCompletionDone( completions ): @@ -319,7 +325,7 @@ class PostComplete_test(): eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() ) - def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( + def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa self, *args ): completions = [ BuildCompletion( None ) ] with self._SetupForCsharpCompletionDone( completions ): @@ -340,7 +346,7 @@ class PostComplete_test(): eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() ) - def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( + def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa self, *args ): info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ] completions = [ BuildCompletion( *info ), @@ -353,7 +359,7 @@ class PostComplete_test(): self.ycm.GetCompletionsUserMayHaveCompleted() ) - def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( + def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa self ): info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ] completions = [ BuildCompletion( insertion_text = info[ 0 ] ), @@ -391,7 +397,7 @@ class PostComplete_test(): ok_( not vimsupport.InsertNamespace.called ) - def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test( + def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test( self, *args ): completions = [ BuildCompletion( None ) ] with self._SetupForCsharpCompletionDone( completions ): diff --git a/python/ycm/tests/syntax_parse_test.py b/python/ycm/tests/syntax_parse_test.py index d1270677..dc2e61ae 100644 --- a/python/ycm/tests/syntax_parse_test.py +++ b/python/ycm/tests/syntax_parse_test.py @@ -146,9 +146,7 @@ def KeywordsFromSyntaxListOutput_Basic_test(): syntax_parse._KeywordsFromSyntaxListOutput( """ foogroup xxx foo bar zoo goo - links to Statement""" - ) - ) + links to Statement""" ) ) def KeywordsFromSyntaxListOutput_Function_test(): @@ -156,16 +154,14 @@ def KeywordsFromSyntaxListOutput_Function_test(): syntax_parse._KeywordsFromSyntaxListOutput( """ foogroup xxx foo bar zoo goo - links to Function""" - ) - ) + links to Function""" ) ) def KeywordsFromSyntaxListOutput_ContainedArgAllowed_test(): assert_that( syntax_parse._KeywordsFromSyntaxListOutput( """ phpFunctions xxx contained gzclose yaz_syntax html_entity_decode fbsql_read_blob png2wbmp mssql_init cpdf_set_title gztell fbsql_insert_id empty cpdf_restore mysql_field_type closelog swftext ldap_search curl_errno gmp_div_r mssql_data_seek getmyinode printer_draw_pie mcve_initconn ncurses_getmaxyx defined contained replace_child has_attributes specified insertdocument assign node_name hwstat addshape get_attribute_node html_dump_mem userlist - links to Function""" ), + links to Function""" ), # noqa has_items( 'gzclose', 'userlist', 'ldap_search' ) ) @@ -177,9 +173,7 @@ foogroup xxx foo bar zoo goo links to Statement Spell cluster=NONE -NoSpell cluster=NONE""" - ) - ) +NoSpell cluster=NONE""" ) ) def KeywordsFromSyntaxListOutput_MultipleStatementGroups_test(): @@ -188,9 +182,7 @@ def KeywordsFromSyntaxListOutput_MultipleStatementGroups_test(): foogroup xxx foo bar links to Statement bargroup xxx zoo goo - links to Statement""" - ) - ) + links to Statement""" ) ) def KeywordsFromSyntaxListOutput_StatementAndTypeGroups_test(): @@ -199,9 +191,7 @@ def KeywordsFromSyntaxListOutput_StatementAndTypeGroups_test(): foogroup xxx foo bar links to Statement bargroup xxx zoo goo - links to Type""" - ) - ) + links to Type""" ) ) def KeywordsFromSyntaxListOutput_StatementHierarchy_test(): @@ -212,9 +202,7 @@ baa xxx foo bar Foo xxx zoo goo links to Bar Bar xxx qux moo - links to Statement""" - ) - ) + links to Statement""" ) ) def KeywordsFromSyntaxListOutput_TypeHierarchy_test(): @@ -225,9 +213,7 @@ baa xxx foo bar Foo xxx zoo goo links to Bar Bar xxx qux moo - links to Type""" - ) - ) + links to Type""" ) ) def KeywordsFromSyntaxListOutput_StatementAndTypeHierarchy_test(): @@ -244,9 +230,7 @@ sBaa xxx na bar sFoo xxx zoo nb links to sBar sBar xxx qux nc - links to Statement""" - ) - ) + links to Statement""" ) ) def SyntaxGroupsFromOutput_Basic_test(): @@ -263,8 +247,7 @@ def ExtractKeywordsFromGroup_Basic_test(): syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [ 'foo bar', 'zoo goo', - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_Commas_test(): @@ -272,8 +255,7 @@ def ExtractKeywordsFromGroup_Commas_test(): syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [ 'foo, bar,', 'zoo goo', - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_WithLinksTo_test(): @@ -282,8 +264,7 @@ def ExtractKeywordsFromGroup_WithLinksTo_test(): 'foo bar', 'zoo goo', 'links to Statement' - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_KeywordStarts_test(): @@ -292,8 +273,7 @@ def ExtractKeywordsFromGroup_KeywordStarts_test(): 'foo bar', 'transparent boo baa', 'zoo goo', - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_KeywordMiddle_test(): @@ -301,8 +281,7 @@ def ExtractKeywordsFromGroup_KeywordMiddle_test(): syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [ 'foo oneline bar', 'zoo goo', - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_KeywordAssign_test(): @@ -310,8 +289,7 @@ def ExtractKeywordsFromGroup_KeywordAssign_test(): syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [ 'foo end=zoo((^^//)) bar', 'zoo goo', - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_KeywordAssignAndMiddle_test(): @@ -319,8 +297,7 @@ def ExtractKeywordsFromGroup_KeywordAssignAndMiddle_test(): syntax_parse._ExtractKeywordsFromGroup( syntax_parse.SyntaxGroup('', [ 'foo end=zoo((^^//)) transparent bar', 'zoo goo', - ] ) ) - ) + ] ) ) ) def ExtractKeywordsFromGroup_ContainedSyntaxArgAllowed_test(): @@ -329,5 +306,4 @@ def ExtractKeywordsFromGroup_ContainedSyntaxArgAllowed_test(): 'contained foo zoq', 'contained bar goo', 'far', - ] ) ) - ) + ] ) ) ) diff --git a/python/ycm/unsafe_thread_pool_executor.py b/python/ycm/unsafe_thread_pool_executor.py index 132d497d..666aebcf 100644 --- a/python/ycm/unsafe_thread_pool_executor.py +++ b/python/ycm/unsafe_thread_pool_executor.py @@ -47,6 +47,7 @@ class _WorkItem(object): else: self.future.set_result(result) + def _worker(executor_reference, work_queue): try: while True: @@ -66,6 +67,7 @@ def _worker(executor_reference, work_queue): except BaseException: _base.LOGGER.critical('Exception in worker', exc_info=True) + class UnsafeThreadPoolExecutor(_base.Executor): def __init__(self, max_workers): """Initializes a new ThreadPoolExecutor instance. @@ -116,4 +118,3 @@ class UnsafeThreadPoolExecutor(_base.Executor): for t in self._threads: t.join() shutdown.__doc__ = _base.Executor.shutdown.__doc__ - diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 514c1d05..6b8c0a43 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -959,4 +959,3 @@ def _SetUpLoadedBuffer( command, filename, fix, position, watch ): if position == 'end': vim.command( 'silent! normal G zz' ) - diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 40a6409f..21ce5240 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -55,6 +55,7 @@ try: except ImportError: USE_ULTISNIPS_DATA = False + def PatchNoProxy(): current_value = os.environ.get('no_proxy', '') additions = '127.0.0.1,localhost' @@ -372,7 +373,10 @@ class YouCompleteMe( object ): item = ConvertCompletionDataToVimData( completion ) match_keys = ( [ "word", "abbr", "menu", "info" ] if full_match_only else [ 'word' ] ) - matcher = lambda key: completed.get( key, "" ) == item.get( key, "" ) + + def matcher( key ): + return completed.get( key, "" ) == item.get( key, "" ) + if all( [ matcher( i ) for i in match_keys ] ): yield completion @@ -443,7 +447,7 @@ class YouCompleteMe( object ): if len( namespaces ) > 1: choices = [ "{0} {1}".format( i + 1, n ) - for i,n in enumerate( namespaces ) ] + for i, n in enumerate( namespaces ) ] choice = vimsupport.PresentDialog( "Insert which namespace:", choices ) if choice < 0: return @@ -664,6 +668,6 @@ def _AddUltiSnipsDataIfNeeded( extra_data ): # UltiSnips_Manager._snips() returns a class instance where: # class.trigger - name of snippet trigger word ( e.g. defn or testcase ) # class.description - description of the snippet - extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger, - 'description': x.description - } for x in rawsnips ] + extra_data[ 'ultisnips_snippets' ] = [ + { 'trigger': x.trigger, 'description': x.description } for x in rawsnips + ] diff --git a/run_tests.py b/run_tests.py index 705b803e..cd712265 100755 --- a/run_tests.py +++ b/run_tests.py @@ -34,12 +34,11 @@ sys.path.insert( 1, p.abspath( p.join( DIR_OF_YCMD_THIRD_PARTY, import argparse + def RunFlake8(): print( 'Running flake8' ) subprocess.check_call( [ 'flake8', - '--select=F,C9', - '--max-complexity=10', p.join( DIR_OF_THIS_SCRIPT, 'python' ) ] ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..70d6d70a --- /dev/null +++ b/tox.ini @@ -0,0 +1,4 @@ +[flake8] +ignore = E111,E114,E121,E125,E126,E127,E128,E129,E131,E133,E201,E202,E203,E211,E221,E222,E241,E251,E261,E303,E402,W503 +max-complexity = 10 +max-line-length = 80