Skip to content

Commit a6b7b28

Browse files
authored
Use f-strings wherever possible (#10)
1 parent 8aee003 commit a6b7b28

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

pylsp_jsonrpc/dispatchers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MethodDispatcher:
1616
"""
1717

1818
def __getitem__(self, item):
19-
method_name = 'm_{}'.format(_method_to_string(item))
19+
method_name = f'm_{_method_to_string(item)}'
2020
if hasattr(self, method_name):
2121
method = getattr(self, method_name)
2222

pylsp_jsonrpc/streams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _content_length(line):
7474
try:
7575
return int(value)
7676
except ValueError as e:
77-
raise ValueError("Invalid Content-Length header: {}".format(value)) from e
77+
raise ValueError(f"Invalid Content-Length header: {value}") from e
7878

7979
return None
8080

@@ -100,9 +100,9 @@ def write(self, message):
100100
content_length = len(body) if isinstance(body, bytes) else len(body.encode('utf-8'))
101101

102102
response = (
103-
"Content-Length: {}\r\n"
104-
"Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n"
105-
"{}".format(content_length, body)
103+
f"Content-Length: {content_length}\r\n"
104+
f"Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n"
105+
f"{body}"
106106
)
107107

108108
self._wfile.write(response.encode('utf-8'))

test/test_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def assert_consumer_error(consumer_mock, exception):
332332

333333
def await_assertion(condition, timeout=3.0, interval=0.1, exc=None):
334334
if timeout <= 0:
335-
raise exc if exc else AssertionError("Failed to wait for condition %s" % condition)
335+
raise exc if exc else AssertionError(f"Failed to wait for condition {condition}")
336336
try:
337337
condition()
338338
except AssertionError as e:

test/test_streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __json__(self):
9898
dif = int(self.timestamp())
9999
else:
100100
dif = int((self - datetime.datetime(1970, 1, 1)).total_seconds())
101-
return '{0}'.format(dif)
101+
return f'{dif}'
102102

103103

104104
def test_writer_bad_message(wfile, writer):

0 commit comments

Comments
 (0)