Skip to content

Commit 80ac5fa

Browse files
committed
Undo black formatting from commit 1489e85
1 parent 1489e85 commit 80ac5fa

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

mypy_ls/plugin.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
File that contains the pylsp plugin mypy-ls.
3+
File that contains the python-lsp-server plugin mypy-ls.
44
55
Created on Fri Jul 10 09:53:57 2020
66
@@ -27,9 +27,7 @@
2727
tmpFile: Optional[IO[str]] = None
2828

2929

30-
def parse_line(
31-
line: str, document: Optional[Document] = None
32-
) -> Optional[Dict[str, Any]]:
30+
def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[str, Any]]:
3331
"""
3432
Return a language-server diagnostic from a line of the Mypy error report.
3533
@@ -56,44 +54,42 @@ def parse_line(
5654
if file_path != "<string>": # live mode
5755
# results from other files can be included, but we cannot return
5856
# them.
59-
if document and document.path and not document.path.endswith(file_path):
60-
log.warning(
61-
"discarding result for %s against %s", file_path, document.path
62-
)
57+
if document and document.path and not document.path.endswith(
58+
file_path):
59+
log.warning("discarding result for %s against %s", file_path,
60+
document.path)
6361
return None
6462

6563
lineno = int(linenoStr or 1) - 1 # 0-based line number
6664
offset = int(offsetStr or 1) - 1 # 0-based offset
6765
errno = 2
68-
if severity == "error":
66+
if severity == 'error':
6967
errno = 1
7068
diag: Dict[str, Any] = {
71-
"source": "mypy",
72-
"range": {
73-
"start": {"line": lineno, "character": offset},
69+
'source': 'mypy',
70+
'range': {
71+
'start': {'line': lineno, 'character': offset},
7472
# There may be a better solution, but mypy does not provide end
75-
"end": {"line": lineno, "character": offset + 1},
73+
'end': {'line': lineno, 'character': offset + 1}
7674
},
77-
"message": msg,
78-
"severity": errno,
75+
'message': msg,
76+
'severity': errno
7977
}
8078
if document:
8179
# although mypy does not provide the end of the affected range, we
8280
# can make a good guess by highlighting the word that Mypy flagged
83-
word = document.word_at_position(diag["range"]["start"])
81+
word = document.word_at_position(diag['range']['start'])
8482
if word:
85-
diag["range"]["end"]["character"] = diag["range"]["start"][
86-
"character"
87-
] + len(word)
83+
diag['range']['end']['character'] = (
84+
diag['range']['start']['character'] + len(word))
8885

8986
return diag
9087
return None
9188

9289

9390
@hookimpl
94-
def pylsp_lint(
95-
config: Config, workspace: Workspace, document: Document, is_saved: bool
96-
) -> List[Dict[str, Any]]:
91+
def pylsp_lint(config: Config, workspace: Workspace, document: Document,
92+
is_saved: bool) -> List[Dict[str, Any]]:
9793
"""
9894
Lints.
9995
@@ -114,25 +110,27 @@ def pylsp_lint(
114110
List of the linting data.
115111
116112
"""
117-
settings = config.plugin_settings("mypy-ls")
118-
live_mode = settings.get("live_mode", True)
119-
args = ["--incremental", "--show-column-numbers", "--follow-imports", "silent"]
113+
settings = config.plugin_settings('mypy-ls')
114+
live_mode = settings.get('live_mode', True)
115+
args = ['--incremental',
116+
'--show-column-numbers',
117+
'--follow-imports', 'silent']
120118

121119
global tmpFile
122120
if live_mode and not is_saved and tmpFile:
123121
tmpFile = open(tmpFile.name, "w")
124122
tmpFile.write(document.source)
125123
tmpFile.close()
126-
args.extend(["--shadow-file", document.path, tmpFile.name])
124+
args.extend(['--shadow-file', document.path, tmpFile.name])
127125
elif not is_saved:
128126
return []
129127

130128
if mypyConfigFile:
131-
args.append("--config-file")
129+
args.append('--config-file')
132130
args.append(mypyConfigFile)
133131
args.append(document.path)
134-
if settings.get("strict", False):
135-
args.append("--strict")
132+
if settings.get('strict', False):
133+
args.append('--strict')
136134

137135
report, errors, _ = mypy_api.run(args)
138136

@@ -189,11 +187,10 @@ def init(workspace: str) -> Dict[str, str]:
189187
configuration = eval(file.read())
190188
global mypyConfigFile
191189
mypyConfigFile = findConfigFile(workspace, "mypy.ini")
192-
if ("enabled" not in configuration or configuration["enabled"]) and (
193-
"live_mode" not in configuration or configuration["live_mode"]
194-
):
190+
if (("enabled" not in configuration or configuration["enabled"])
191+
and ("live_mode" not in configuration or configuration["live_mode"])):
195192
global tmpFile
196-
tmpFile = tempfile.NamedTemporaryFile("w", delete=False)
193+
tmpFile = tempfile.NamedTemporaryFile('w', delete=False)
197194
tmpFile.close()
198195
return configuration
199196

test/test_plugin.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
TYPE_ERR_MSG = '"Dict[<nothing>, <nothing>]" has no attribute "append"'
1313

1414
TEST_LINE = 'test_plugin.py:279:8: error: "Request" has no attribute "id"'
15-
TEST_LINE_WITHOUT_COL = "test_plugin.py:279: " 'error: "Request" has no attribute "id"'
16-
TEST_LINE_WITHOUT_LINE = "test_plugin.py: " 'error: "Request" has no attribute "id"'
15+
TEST_LINE_WITHOUT_COL = ('test_plugin.py:279: '
16+
'error: "Request" has no attribute "id"')
17+
TEST_LINE_WITHOUT_LINE = ('test_plugin.py: '
18+
'error: "Request" has no attribute "id"')
1719

1820

1921
@pytest.fixture
@@ -25,6 +27,7 @@ def workspace(tmpdir):
2527

2628

2729
class FakeConfig(object):
30+
2831
def __init__(self):
2932
self._root_path = "C:"
3033

@@ -47,40 +50,40 @@ def test_plugin(workspace):
4750

4851
assert len(diags) == 1
4952
diag = diags[0]
50-
assert diag["message"] == TYPE_ERR_MSG
51-
assert diag["range"]["start"] == {"line": 0, "character": 0}
52-
assert diag["range"]["end"] == {"line": 0, "character": 1}
53+
assert diag['message'] == TYPE_ERR_MSG
54+
assert diag['range']['start'] == {'line': 0, 'character': 0}
55+
assert diag['range']['end'] == {'line': 0, 'character': 1}
5356

5457

5558
def test_parse_full_line(workspace):
5659
doc = Document(DOC_URI, workspace)
5760
diag = plugin.parse_line(TEST_LINE, doc)
58-
assert diag["message"] == '"Request" has no attribute "id"'
59-
assert diag["range"]["start"] == {"line": 278, "character": 7}
60-
assert diag["range"]["end"] == {"line": 278, "character": 8}
61+
assert diag['message'] == '"Request" has no attribute "id"'
62+
assert diag['range']['start'] == {'line': 278, 'character': 7}
63+
assert diag['range']['end'] == {'line': 278, 'character': 8}
6164

6265

6366
def test_parse_line_without_col(workspace):
6467
doc = Document(DOC_URI, workspace)
6568
diag = plugin.parse_line(TEST_LINE_WITHOUT_COL, doc)
66-
assert diag["message"] == '"Request" has no attribute "id"'
67-
assert diag["range"]["start"] == {"line": 278, "character": 0}
68-
assert diag["range"]["end"] == {"line": 278, "character": 1}
69+
assert diag['message'] == '"Request" has no attribute "id"'
70+
assert diag['range']['start'] == {'line': 278, 'character': 0}
71+
assert diag['range']['end'] == {'line': 278, 'character': 1}
6972

7073

7174
def test_parse_line_without_line(workspace):
7275
doc = Document(DOC_URI, workspace)
7376
diag = plugin.parse_line(TEST_LINE_WITHOUT_LINE, doc)
74-
assert diag["message"] == '"Request" has no attribute "id"'
75-
assert diag["range"]["start"] == {"line": 0, "character": 0}
76-
assert diag["range"]["end"] == {"line": 0, "character": 6}
77+
assert diag['message'] == '"Request" has no attribute "id"'
78+
assert diag['range']['start'] == {'line': 0, 'character': 0}
79+
assert diag['range']['end'] == {'line': 0, 'character': 6}
7780

7881

79-
@pytest.mark.parametrize("word,bounds", [("", (7, 8)), ("my_var", (7, 13))])
82+
@pytest.mark.parametrize('word,bounds', [('', (7, 8)), ('my_var', (7, 13))])
8083
def test_parse_line_with_context(monkeypatch, word, bounds, workspace):
8184
doc = Document(DOC_URI, workspace)
82-
monkeypatch.setattr(Document, "word_at_position", lambda *args: word)
85+
monkeypatch.setattr(Document, 'word_at_position', lambda *args: word)
8386
diag = plugin.parse_line(TEST_LINE, doc)
84-
assert diag["message"] == '"Request" has no attribute "id"'
85-
assert diag["range"]["start"] == {"line": 278, "character": bounds[0]}
86-
assert diag["range"]["end"] == {"line": 278, "character": bounds[1]}
87+
assert diag['message'] == '"Request" has no attribute "id"'
88+
assert diag['range']['start'] == {'line': 278, 'character': bounds[0]}
89+
assert diag['range']['end'] == {'line': 278, 'character': bounds[1]}

0 commit comments

Comments
 (0)