Skip to content

Commit 87471bb

Browse files
committed
Updates typing in jsonrpc
1 parent 039e092 commit 87471bb

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

fortls/jsonrpc.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
log = logging.getLogger(__name__)
2020

2121

22-
def path_from_uri(uri):
22+
def path_from_uri(uri: str) -> str:
2323
# Convert file uri to path (strip html like head part)
2424
if not uri.startswith("file://"):
2525
return os.path.abspath(uri)
@@ -30,7 +30,7 @@ def path_from_uri(uri):
3030
return os.path.normpath(unquote(path))
3131

3232

33-
def path_to_uri(path):
33+
def path_to_uri(path: str) -> str:
3434
# Convert path to file uri (add html like head part)
3535
if os.name == "nt":
3636
return "file:///" + quote(path.replace("\\", "/"))
@@ -88,9 +88,7 @@ def _read_header_content_length(self, line):
8888
try:
8989
return int(value)
9090
except ValueError:
91-
raise JSONRPC2ProtocolError(
92-
"Invalid Content-Length header: {0}".format(value)
93-
)
91+
raise JSONRPC2ProtocolError(f"Invalid Content-Length header: {value}")
9492

9593
def _receive(self):
9694
line = self.conn.readline()
@@ -130,9 +128,9 @@ def _send(self, body):
130128
body = json.dumps(body, separators=(",", ":"))
131129
content_length = len(body)
132130
response = (
133-
"Content-Length: {0}\r\n"
131+
f"Content-Length: {content_length}\r\n"
134132
"Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n"
135-
"{1}".format(content_length, body)
133+
f"{body}"
136134
)
137135
self.conn.write(response)
138136
log.debug("SEND %s", body)
@@ -239,9 +237,9 @@ def write_rpc_request(rid, method, params):
239237
body = json.dumps(body, separators=(",", ":"))
240238
content_length = len(body)
241239
return (
242-
"Content-Length: {0}\r\n"
240+
f"Content-Length: {content_length}\r\n"
243241
"Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n"
244-
"{1}".format(content_length, body)
242+
f"{body}"
245243
)
246244

247245

@@ -254,9 +252,9 @@ def write_rpc_notification(method, params):
254252
body = json.dumps(body, separators=(",", ":"))
255253
content_length = len(body)
256254
return (
257-
"Content-Length: {0}\r\n"
255+
f"Content-Length: {content_length}\r\n"
258256
"Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n"
259-
"{1}".format(content_length, body)
257+
f"{body}"
260258
)
261259

262260

@@ -270,9 +268,7 @@ def read_header_content_length(line):
270268
try:
271269
return int(value)
272270
except ValueError:
273-
raise JSONRPC2ProtocolError(
274-
"Invalid Content-Length header: {0}".format(value)
275-
)
271+
raise JSONRPC2ProtocolError(f"Invalid Content-Length header: {value}")
276272

277273
def receive_next():
278274
line = content.readline()

0 commit comments

Comments
 (0)