Skip to content

Commit c665291

Browse files
authored
Enable pylint (#202)
1 parent 7a66037 commit c665291

16 files changed

+62
-56
lines changed

pyls/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ def _binary_stdio():
8080
PY3K = sys.version_info >= (3, 0)
8181

8282
if PY3K:
83+
# pylint: disable=no-member
8384
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
8485
else:
8586
# Python 2 on Windows opens sys.stdin in text mode, and
8687
# binary data that read from it becomes corrupted on \r\n
8788
if sys.platform == "win32":
8889
# set sys.stdin to binary mode
90+
# pylint: disable=no-member,import-error
8991
import os
9092
import msvcrt
9193
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)

pyls/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def find_parents(root, path, names):
6565

6666

6767
def list_to_string(value):
68-
return ",".join(value) if type(value) == list else value
68+
return ",".join(value) if isinstance(value, list) else value
6969

7070

7171
def merge_dicts(dict_a, dict_b):
@@ -122,7 +122,7 @@ def format_docstring(contents):
122122
Until we can find a fast enough way of discovering and parsing each format,
123123
we can do a little better by at least preserving indentation.
124124
"""
125-
contents = contents.replace('\t', '\u00A0' * 4)
126-
contents = contents.replace(' ', '\u00A0' * 2)
125+
contents = contents.replace('\t', u'\u00A0' * 4)
126+
contents = contents.replace(' ', u'\u00A0' * 2)
127127
contents = contents.replace('*', '\\*')
128128
return contents

pyls/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
# pylint: skip-file
22
# This file helps to compute a version number in source trees obtained from
33
# git-archive tarball (such as those provided by githubs download-from-tag
44
# feature). Distribution tarballs (built by setup.py sdist) and build

pyls/config/flake8_conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import logging
33
import os
4-
from .source import ConfigSource
54
from pyls._utils import find_parents
5+
from .source import ConfigSource
66

77
log = logging.getLogger(__name__)
88

@@ -33,8 +33,7 @@ def user_config(self):
3333
def _user_config_file(self):
3434
if self.is_windows:
3535
return os.path.expanduser('~\\.flake8')
36-
else:
37-
return os.path.join(self.xdg_home, 'flake8')
36+
return os.path.join(self.xdg_home, 'flake8')
3837

3938
def project_config(self, document_path):
4039
files = find_parents(self.root_path, document_path, PROJECT_CONFIGS)

pyls/config/pycodestyle_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import pycodestyle
3-
from .source import ConfigSource
43
from pyls._utils import find_parents
4+
from .source import ConfigSource
55

66

77
CONFIG_KEY = 'pycodestyle'

pyls/language_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):
1515

1616
def setup(self):
1717
super(_StreamHandlerWrapper, self).setup()
18+
# pylint: disable=no-member
1819
self.delegate = self.DELEGATE_CLASS(self.rfile, self.wfile)
1920

2021
def handle(self):
@@ -62,7 +63,7 @@ def __getitem__(self, item):
6263
def wrapped(*args, **kwargs):
6364
try:
6465
return func(*args, **kwargs)
65-
except: # pylint: disable=bare-except
66+
except:
6667
log.exception("CAUGHT")
6768
raise
6869
return wrapped
@@ -77,7 +78,7 @@ class LanguageServer(MethodJSONRPCServer):
7778
root_uri = None
7879
init_opts = None
7980

80-
def capabilities(self):
81+
def capabilities(self): # pylint: disable=no-self-use
8182
return {}
8283

8384
def initialize(self, root_uri, init_opts, process_id):

pyls/plugins/format.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def pyls_format_document(document):
1414

1515

1616
@hookimpl
17-
def pyls_format_range(document, range):
17+
def pyls_format_range(document, range): # pylint: disable=redefined-builtin
1818
# First we 'round' the range up/down to full lines only
1919
range['start']['character'] = 0
2020
range['end']['line'] += 1
@@ -32,25 +32,25 @@ def pyls_format_range(document, range):
3232

3333

3434
def _format(document, lines=None):
35-
new_source, changed = FormatCode(
36-
document.source,
37-
lines=lines,
38-
filename=document.filename,
39-
style_config=file_resources.GetDefaultStyleForDir(
40-
os.path.dirname(document.filename)
41-
)
35+
new_source, changed = FormatCode(
36+
document.source,
37+
lines=lines,
38+
filename=document.filename,
39+
style_config=file_resources.GetDefaultStyleForDir(
40+
os.path.dirname(document.filename)
4241
)
43-
44-
if not changed:
45-
return []
46-
47-
# I'm too lazy at the moment to parse diffs into TextEdit items
48-
# So let's just return the entire file...
49-
return [{
50-
'range': {
51-
'start': {'line': 0, 'character': 0},
52-
# End char 0 of the line after our document
53-
'end': {'line': len(document.lines), 'character': 0}
54-
},
55-
'newText': new_source
56-
}]
42+
)
43+
44+
if not changed:
45+
return []
46+
47+
# I'm too lazy at the moment to parse diffs into TextEdit items
48+
# So let's just return the entire file...
49+
return [{
50+
'range': {
51+
'start': {'line': 0, 'character': 0},
52+
# End char 0 of the line after our document
53+
'end': {'line': len(document.lines), 'character': 0}
54+
},
55+
'newText': new_source
56+
}]

pyls/plugins/hover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def pyls_hover(document, position):
1313
# Find an exact match for a completion
1414
definitions = [d for d in definitions if d.name == word]
1515

16-
if len(definitions) == 0:
16+
if not definitions:
1717
# :(
1818
return {'contents': ''}
1919

pyls/plugins/pycodestyle_lint.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,24 @@ def __init__(self, options=None):
3636
self.diagnostics = []
3737
super(PyCodeStyleDiagnosticReport, self).__init__(options=options)
3838

39-
def error(self, lineno, offset, text, check):
39+
def error(self, line_number, offset, text, check):
4040
# PyCodeStyle will sometimes give you an error the line after the end of the file
4141
# e.g. no newline at end of file
4242
# In that case, the end offset should just be some number ~100
4343
# (because why not? There's nothing to underline anyways)
44-
range = {
45-
'start': {'line': lineno - 1, 'character': offset},
44+
err_range = {
45+
'start': {'line': line_number - 1, 'character': offset},
4646
'end': {
4747
# FIXME: It's a little naiive to mark until the end of the line, can we not easily do better?
48-
'line': lineno - 1, 'character': 100 if lineno > len(self.lines) else len(self.lines[lineno - 1])
48+
'line': line_number - 1,
49+
'character': 100 if line_number > len(self.lines) else len(self.lines[line_number - 1])
4950
},
5051
}
5152
code, _message = text.split(" ", 1)
5253

5354
self.diagnostics.append({
5455
'source': 'pycodestyle',
55-
'range': range,
56+
'range': err_range,
5657
'message': text,
5758
'code': code,
5859
# Are style errors really ever errors?

pyls/plugins/pyflakes_lint.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ def __init__(self, lines):
1919
def unexpectedError(self, filename, msg): # pragma: no cover
2020
pass
2121

22-
def syntaxError(self, filename, msg, lineno, offset, text):
23-
range = {
22+
def syntaxError(self, _filename, msg, lineno, offset, text):
23+
err_range = {
2424
'start': {'line': lineno - 1, 'character': offset},
2525
'end': {'line': lineno - 1, 'character': offset + len(text)},
2626
}
2727
self.diagnostics.append({
2828
'source': 'pyflakes',
29-
'range': range,
29+
'range': err_range,
3030
'message': msg,
3131
'severity': lsp.DiagnosticSeverity.Error,
3232
})
3333

3434
def flake(self, message):
3535
""" Get message like <filename>:<lineno>: <msg> """
36-
range = {
36+
err_range = {
3737
'start': {'line': message.lineno - 1, 'character': message.col},
3838
'end': {'line': message.lineno - 1, 'character': len(self.lines[message.lineno - 1])},
3939
}
4040
self.diagnostics.append({
4141
'source': 'pyflakes',
42-
'range': range,
42+
'range': err_range,
4343
'message': message.message % message.message_args,
4444
'severity': lsp.DiagnosticSeverity.Warning
4545
})

pyls/plugins/signature.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
log = logging.getLogger(__name__)
77

8-
SPHINX = re.compile("\s*:param\s+(?P<param>\w+):\s*(?P<doc>[^\\n]+)")
9-
EPYDOC = re.compile("\s*@param\s+(?P<param>\w+):\s*(?P<doc>[^\\n]+)")
10-
GOOGLE = re.compile("\s*(?P<param>\w+).*:\s*(?P<doc>[^\\n]+)")
8+
SPHINX = re.compile(r"\s*:param\s+(?P<param>\w+):\s*(?P<doc>[^\n]+)")
9+
EPYDOC = re.compile(r"\s*@param\s+(?P<param>\w+):\s*(?P<doc>[^\n]+)")
10+
GOOGLE = re.compile(r"\s*(?P<param>\w+).*:\s*(?P<doc>[^\n]+)")
1111

1212
DOC_REGEX = [SPHINX, EPYDOC, GOOGLE]
1313

@@ -16,7 +16,7 @@
1616
def pyls_signature_help(document, position):
1717
signatures = document.jedi_script(position).call_signatures()
1818

19-
if len(signatures) == 0:
19+
if not signatures:
2020
return {'signatures': []}
2121

2222
s = signatures[0]
@@ -26,7 +26,7 @@ def pyls_signature_help(document, position):
2626
}
2727

2828
# If there are params, add those
29-
if len(s.params) > 0:
29+
if s.params:
3030
sig['parameters'] = [{
3131
'label': p.name,
3232
'documentation': _param_docs(s.docstring(), p.name)

pyls/plugins/symbols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _container(definition):
3939
# as children of the module.
4040
if parent.parent():
4141
return parent.name
42-
except:
42+
except: # pylint: disable=bare-except
4343
pass
4444

4545

pyls/python_ls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
class PythonLanguageServer(LanguageServer):
16+
# pylint: disable=too-many-public-methods,redefined-builtin
1617

1718
workspace = None
1819
config = None
@@ -148,14 +149,14 @@ def m_text_document__hover(self, textDocument=None, position=None, **_kwargs):
148149
def m_text_document__document_symbol(self, textDocument=None, **_kwargs):
149150
return self.document_symbols(textDocument['uri'])
150151

151-
def m_text_document__formatting(self, textDocument=None, options=None, **_kwargs):
152+
def m_text_document__formatting(self, textDocument=None, _options=None, **_kwargs):
152153
# For now we're ignoring formatting options.
153154
return self.format_document(textDocument['uri'])
154155

155156
def m_text_document__rename(self, textDocument=None, position=None, newName=None, **_kwargs):
156157
return self.rename(textDocument['uri'], position, newName)
157158

158-
def m_text_document__range_formatting(self, textDocument=None, range=None, options=None, **_kwargs):
159+
def m_text_document__range_formatting(self, textDocument=None, range=None, _options=None, **_kwargs):
159160
# Again, we'll ignore formatting options for now.
160161
return self.format_range(textDocument['uri'], range)
161162

pyls/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def handle(self):
5656
on_result(msg['result'])
5757
elif 'error' in msg and on_error:
5858
on_error(msg['error'])
59-
except Exception:
59+
except: # pylint: disable=bare-except
6060
log.exception("Language server exiting due to uncaught exception")
6161
break
6262

pyls/workspace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222

2323
def get_submodules(mod):
2424
"""Get all submodules of a given module"""
25-
def catch_exceptions(module):
25+
def catch_exceptions(_module):
2626
pass
27+
2728
try:
2829
m = __import__(mod)
2930
submodules = [mod]
30-
submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.',
31-
catch_exceptions)
31+
submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.', catch_exceptions)
3232
for sm in submods:
3333
sm_name = sm[1]
3434
submodules.append(sm_name)
3535
except ImportError:
3636
return []
37-
except Exception:
37+
except: # pylint: disable=bare-except
3838
return [mod]
3939
return submodules
4040

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ deps =
2323
pytest
2424
coverage
2525
pytest-cov
26+
pylint
2627

2728
[testenv:lint]
2829
commands =
30+
pylint pyls
2931
pycodestyle pyls
3032
pyflakes pyls

0 commit comments

Comments
 (0)