Skip to content

Commit 3e56747

Browse files
committed
Useful pylint fixes
After combing through all the stuff pylint has found, this seems to me the useful part. The only questionable thing here, I think, could be the stuff related to `open()` and explicit encoding argument. This changes behaviour! Without specifying, the encoding is platform dependent. See https://docs.python.org/3/library/functions.html#open for details. Fixes #1672
1 parent 8b61f19 commit 3e56747

29 files changed

+65
-80
lines changed

.ycm_extra_conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
# For more information, please refer to <http://unlicense.org/>
3030

3131
from sysconfig import get_path
32-
import platform
3332
import os.path as p
34-
import subprocess
3533

3634
DIR_OF_THIS_SCRIPT = p.abspath( p.dirname( __file__ ) )
3735
DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' )
@@ -120,7 +118,7 @@ def FindCorrespondingSourceFile( filename ):
120118
def PathToPythonUsedDuringBuild():
121119
try:
122120
filepath = p.join( DIR_OF_THIS_SCRIPT, 'PYTHON_USED_DURING_BUILDING' )
123-
with open( filepath ) as f:
121+
with open( filepath, encoding = 'utf8' ) as f:
124122
return f.read().strip()
125123
except OSError:
126124
return None

build.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def UseVsWhere( quiet, vswhere_args ):
123123
latest_full_v = subprocess.check_output( vswhere_args ).strip().decode()
124124
if '.' in latest_full_v:
125125
try:
126-
latest_v = int( latest_full_v.split( '.' )[ 0 ] )
126+
latest_v = int( latest_full_v.split( '.', 1 )[ 0 ] )
127127
except ValueError:
128128
raise ValueError( f"{ latest_full_v } is not a version number." )
129129

@@ -481,10 +481,10 @@ def ParseArguments():
481481
DEFAULT_RUST_TOOLCHAIN + '" is tested/'
482482
'supported by the maintainers of YCM/ycmd' )
483483
parser.add_argument( '--java-completer', action = 'store_true',
484-
help = 'Enable Java semantic completion engine.' ),
484+
help = 'Enable Java semantic completion engine.' )
485485
parser.add_argument( '--ts-completer', action = 'store_true',
486486
help = 'Enable JavaScript and TypeScript semantic '
487-
'completion engine.' ),
487+
'completion engine.' )
488488
parser.add_argument( '--system-libclang', action = 'store_true',
489489
help = 'Use system libclang instead of downloading one '
490490
'from llvm.org. NOT RECOMMENDED OR SUPPORTED!' )
@@ -855,7 +855,6 @@ def CleanCsCompleter( build_dir, version ):
855855
if os.path.isfile( file_path ):
856856
os.remove( file_path )
857857
elif os.path.isdir( file_path ):
858-
import shutil
859858
shutil.rmtree( file_path )
860859

861860

@@ -974,14 +973,14 @@ def EnableGoCompleter( args ):
974973

975974
def WriteToolchainVersion( version ):
976975
path = p.join( RUST_ANALYZER_DIR, 'TOOLCHAIN_VERSION' )
977-
with open( path, 'w' ) as f:
976+
with open( path, 'w', encoding = 'utf8' ) as f:
978977
f.write( version )
979978

980979

981980
def ReadToolchainVersion():
982981
try:
983982
filepath = p.join( RUST_ANALYZER_DIR, 'TOOLCHAIN_VERSION' )
984-
with open( filepath ) as f:
983+
with open( filepath, encoding = 'utf8' ) as f:
985984
return f.read().strip()
986985
except OSError:
987986
return None
@@ -1255,7 +1254,7 @@ def Print( msg ):
12551254

12561255
def WritePythonUsedDuringBuild():
12571256
path = p.join( DIR_OF_THIS_SCRIPT, 'PYTHON_USED_DURING_BUILDING' )
1258-
with open( path, 'w' ) as f:
1257+
with open( path, 'w', encoding = 'utf8' ) as f:
12591258
f.write( sys.executable )
12601259

12611260

run_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ def BuildYcmdLibs( args ):
191191
'--core-tests'
192192
]
193193

194-
for key in COMPLETERS:
194+
for key, value in COMPLETERS.items():
195195
if key in args.completers:
196-
build_cmd.extend( COMPLETERS[ key ][ 'build' ] )
196+
build_cmd.extend( value[ 'build' ] )
197197

198198
if args.msvc and platform.system() == 'Windows':
199199
build_cmd.extend( [ '--msvc', str( args.msvc ) ] )

update_clang_headers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def ExtractTar( uncompressed_data, destination ):
3939
tar_file.extractall( destination )
4040

4141
# Determine the directory name
42-
return os.path.join( destination, a_member.name.split( '/' )[ 0 ] )
42+
return os.path.join( destination, a_member.name.split( '/', 1 )[ 0 ] )
4343

4444

4545
def ExtractLZMA( compressed_data, destination ):

update_unicode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def GenerateNormalizationTestCases( output_file ):
607607
JoinUnicodeToUtf8( captures[ 4 ].split() ) + '"},\n' )
608608

609609
res[ -1 ] = res[ -1 ].rstrip( ',\n' )
610-
with open( output_file, 'w' ) as f:
610+
with open( output_file, 'w', encoding = 'utf8' ) as f:
611611
f.writelines( res )
612612

613613

@@ -629,7 +629,7 @@ def GenerateGraphemeBreakTestCases( output_file ):
629629
for x in split_data ] ).rstrip( ',' ) + '}},\n' )
630630

631631
res[ -1 ] = res[ -1 ].rstrip( ',\n' )
632-
with open( output_file, 'w' ) as f:
632+
with open( output_file, 'w', encoding = 'utf8' ) as f:
633633
f.writelines( res )
634634

635635

ycmd/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def ParseArguments():
133133
def SetupLogging( log_level ):
134134
numeric_level = getattr( logging, log_level.upper(), None )
135135
if not isinstance( numeric_level, int ):
136-
raise ValueError( 'Invalid log level: %s' % log_level )
136+
raise ValueError( f'Invalid log level: { log_level }' )
137137

138138
# Has to be called before any call to logging.getLogger()
139139
logging.basicConfig( format = '%(asctime)s - %(levelname)s - %(message)s',

ycmd/completers/cpp/clang_completer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ def DebugInfo( self, request_data ):
436436

437437
database_item = responses.DebugInfoItem(
438438
key = 'compilation database path',
439-
value = '{0}'.format( database_directory ) )
439+
value = f'{ database_directory }' )
440440
flags_item = responses.DebugInfoItem(
441-
key = 'flags', value = '{0}'.format( list( flags ) ) )
441+
key = 'flags', value = f'{ list( flags ) }' )
442442
filename_item = responses.DebugInfoItem(
443443
key = 'translation unit', value = filename )
444444

ycmd/completers/cpp/flags.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,12 @@ def UserIncludePaths( user_flags, filename ):
673673
it = iter( user_flags )
674674
for user_flag in it:
675675
user_flag_len = len( user_flag )
676-
for flag in include_flags:
676+
for flag, container in include_flags.items():
677677
if user_flag.startswith( flag ):
678678
flag_len = len( flag )
679679
include_path = ( next( it ) if user_flag_len == flag_len else
680680
user_flag[ flag_len: ] )
681681
if include_path:
682-
container = include_flags[ flag ]
683682
container.append( ToUnicode( include_path ) )
684683
break
685684
except StopIteration:

ycmd/completers/cs/cs_completer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def _GetSolutionFile( self, filepath ):
393393
return self._solution_for_file[ filepath ]
394394

395395

396-
class CsharpSolutionCompleter( object ):
396+
class CsharpSolutionCompleter:
397397
def __init__( self,
398398
solution_path,
399399
keep_logfiles,

ycmd/completers/language_server/generic_lsp_completer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def __init__( self, user_options, server_settings ):
4848
cmd = utils.FindExecutable( self._command_line[ 0 ] )
4949

5050
if cmd is None:
51-
utils.LOGGER.warn( "Unable to find any executable with the path %s. "
52-
"Cannot use %s completer.",
53-
self._command_line[ 0 ],
54-
self._name )
55-
raise RuntimeError( f"Invalid cmdline: { str( self._command_line ) }" )
51+
utils.LOGGER.warning( "Unable to find any executable with the path %s. "
52+
"Cannot use %s completer.",
53+
self._command_line[ 0 ],
54+
self._name )
55+
raise RuntimeError( f"Invalid cmdline: { self._command_line }" )
5656

5757
self._command_line[ 0 ] = cmd
5858
for idx in range( len( self._command_line ) ):

0 commit comments

Comments
 (0)