Skip to content

Use f-strings wherever possible #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pylsp_jsonrpc/dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MethodDispatcher:
"""

def __getitem__(self, item):
method_name = 'm_{}'.format(_method_to_string(item))
method_name = f'm_{_method_to_string(item)}'
if hasattr(self, method_name):
method = getattr(self, method_name)

Expand Down
8 changes: 4 additions & 4 deletions pylsp_jsonrpc/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _content_length(line):
try:
return int(value)
except ValueError as e:
raise ValueError("Invalid Content-Length header: {}".format(value)) from e
raise ValueError(f"Invalid Content-Length header: {value}") from e

return None

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

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

self._wfile.write(response.encode('utf-8'))
Expand Down
2 changes: 1 addition & 1 deletion test/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def assert_consumer_error(consumer_mock, exception):

def await_assertion(condition, timeout=3.0, interval=0.1, exc=None):
if timeout <= 0:
raise exc if exc else AssertionError("Failed to wait for condition %s" % condition)
raise exc if exc else AssertionError(f"Failed to wait for condition {condition}")
try:
condition()
except AssertionError as e:
Expand Down
2 changes: 1 addition & 1 deletion test/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __json__(self):
dif = int(self.timestamp())
else:
dif = int((self - datetime.datetime(1970, 1, 1)).total_seconds())
return '{0}'.format(dif)
return f'{dif}'


def test_writer_bad_message(wfile, writer):
Expand Down