Skip to content

Commit a2c6894

Browse files
hugovkpgjones
authored andcommitted
Upgrade Python syntax with pyupgrade --py38-plus
1 parent 0a74272 commit a2c6894

File tree

8 files changed

+19
-20
lines changed

8 files changed

+19
-20
lines changed

bench/benchmarks/benchmarks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _run_basic_get_repeatedly():
6060
for _ in range(REPEAT):
6161
time_server_basic_get_with_realistic_headers()
6262
finish = default_timer()
63-
print("{:.1f} requests/sec".format(REPEAT / (finish - start)))
63+
print(f"{REPEAT / (finish - start):.1f} requests/sec")
6464

6565

6666
if __name__ == "__main__":

docs/source/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# h11 documentation build configuration file, created by
54
# sphinx-quickstart on Tue May 3 00:20:14 2016.

docs/source/make-state-diagrams.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ def __init__(self):
3838

3939
def e(self, source, target, label, color, italicize=False, weight=1):
4040
if italicize:
41-
quoted_label = "<<i>{}</i>>".format(label)
41+
quoted_label = f"<<i>{label}</i>>"
4242
else:
43-
quoted_label = '<{}>'.format(label)
43+
quoted_label = f'<{label}>'
4444
self.edges.append(
45-
'{source} -> {target} [\n'
46-
' label={quoted_label},\n'
47-
' color="{color}", fontcolor="{color}",\n'
48-
' weight={weight},\n'
49-
']\n'
50-
.format(**locals()))
45+
f'{source} -> {target} [\n'
46+
f' label={quoted_label},\n'
47+
f' color="{color}", fontcolor="{color}",\n'
48+
f' weight={weight},\n'
49+
f']\n'
50+
)
5151

5252
def write(self, f):
5353
self.edges.sort()
@@ -150,7 +150,7 @@ def make_dot(role, out_path):
150150
else:
151151
(their_state, our_state) = state_pair
152152
edges.e(our_state, updates[role],
153-
"<i>peer in</i><BR/>{}".format(their_state),
153+
f"<i>peer in</i><BR/>{their_state}",
154154
color=_STATE_COLOR)
155155

156156
if role is CLIENT:

examples/trio-server.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(self, stream):
118118
self.conn = h11.Connection(h11.SERVER)
119119
# Our Server: header
120120
self.ident = " ".join(
121-
["h11-example-trio-server/{}".format(h11.__version__), h11.PRODUCT_ID]
121+
[f"h11-example-trio-server/{h11.__version__}", h11.PRODUCT_ID]
122122
).encode("ascii")
123123
# A unique id for this connection, to include in debugging output
124124
# (useful for understanding what's going on if there are multiple
@@ -206,7 +206,7 @@ def basic_headers(self):
206206

207207
def info(self, *args):
208208
# Little debugging method
209-
print("{}:".format(self._obj_id), *args)
209+
print(f"{self._obj_id}:", *args)
210210

211211

212212
################################################################
@@ -253,7 +253,7 @@ async def http_serve(stream):
253253
if type(event) is h11.Request:
254254
await send_echo_response(wrapper, event)
255255
except Exception as exc:
256-
wrapper.info("Error during response handler: {!r}".format(exc))
256+
wrapper.info(f"Error during response handler: {exc!r}")
257257
await maybe_send_error_response(wrapper, exc)
258258

259259
if wrapper.conn.our_state is h11.MUST_CLOSE:
@@ -268,7 +268,7 @@ async def http_serve(stream):
268268
states = wrapper.conn.states
269269
wrapper.info("unexpected state", states, "-- bailing out")
270270
await maybe_send_error_response(
271-
wrapper, RuntimeError("unexpected state {}".format(states))
271+
wrapper, RuntimeError(f"unexpected state {states}")
272272
)
273273
await wrapper.shutdown_and_clean_up()
274274
return
@@ -343,7 +343,7 @@ async def send_echo_response(wrapper, request):
343343

344344

345345
async def serve(port):
346-
print("listening on http://localhost:{}".format(port))
346+
print(f"listening on http://localhost:{port}")
347347
try:
348348
await trio.serve_tcp(http_serve, port)
349349
except KeyboardInterrupt:

h11/_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __init__(
172172
self._max_incomplete_event_size = max_incomplete_event_size
173173
# State and role tracking
174174
if our_role not in (CLIENT, SERVER):
175-
raise ValueError("expected CLIENT or SERVER, not {!r}".format(our_role))
175+
raise ValueError(f"expected CLIENT or SERVER, not {our_role!r}")
176176
self.our_role = our_role
177177
self.their_role: Type[Sentinel]
178178
if our_role is CLIENT:

h11/_state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def _fire_state_triggered_transitions(self) -> None:
358358
def start_next_cycle(self) -> None:
359359
if self.states != {CLIENT: DONE, SERVER: DONE}:
360360
raise LocalProtocolError(
361-
"not in a reusable state. self.states={}".format(self.states)
361+
f"not in a reusable state. self.states={self.states}"
362362
)
363363
# Can't reach DONE/DONE with any of these active, but still, let's be
364364
# sure.

h11/tests/test_against_stdlib_http.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def handle(self) -> None:
104104
def test_h11_as_server() -> None:
105105
with socket_server(H11RequestHandler) as httpd:
106106
host, port = httpd.server_address
107-
url = "http://{}:{}/some-path".format(host, port)
107+
url = f"http://{host}:{port}/some-path"
108108
with closing(urlopen(url)) as f:
109109
assert f.getcode() == 200
110110
data = f.read()

h11/tests/test_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def setup(
879879
) -> Tuple[Connection, Optional[List[bytes]]]:
880880
c = Connection(SERVER)
881881
receive_and_get(
882-
c, "GET / HTTP/{}\r\nHost: a\r\n\r\n".format(http_version).encode("ascii")
882+
c, f"GET / HTTP/{http_version}\r\nHost: a\r\n\r\n".encode("ascii")
883883
)
884884
headers = []
885885
if header:

0 commit comments

Comments
 (0)