Skip to content

Commit

Permalink
Upgrade Python syntax with pyupgrade --py38-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored and pgjones committed Sep 16, 2023
1 parent 0a74272 commit a2c6894
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bench/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _run_basic_get_repeatedly():
for _ in range(REPEAT):
time_server_basic_get_with_realistic_headers()
finish = default_timer()
print("{:.1f} requests/sec".format(REPEAT / (finish - start)))
print(f"{REPEAT / (finish - start):.1f} requests/sec")


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# h11 documentation build configuration file, created by
# sphinx-quickstart on Tue May 3 00:20:14 2016.
Expand Down
18 changes: 9 additions & 9 deletions docs/source/make-state-diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ def __init__(self):

def e(self, source, target, label, color, italicize=False, weight=1):
if italicize:
quoted_label = "<<i>{}</i>>".format(label)
quoted_label = f"<<i>{label}</i>>"
else:
quoted_label = '<{}>'.format(label)
quoted_label = f'<{label}>'
self.edges.append(
'{source} -> {target} [\n'
' label={quoted_label},\n'
' color="{color}", fontcolor="{color}",\n'
' weight={weight},\n'
']\n'
.format(**locals()))
f'{source} -> {target} [\n'
f' label={quoted_label},\n'
f' color="{color}", fontcolor="{color}",\n'
f' weight={weight},\n'
f']\n'
)

def write(self, f):
self.edges.sort()
Expand Down Expand Up @@ -150,7 +150,7 @@ def make_dot(role, out_path):
else:
(their_state, our_state) = state_pair
edges.e(our_state, updates[role],
"<i>peer in</i><BR/>{}".format(their_state),
f"<i>peer in</i><BR/>{their_state}",
color=_STATE_COLOR)

if role is CLIENT:
Expand Down
10 changes: 5 additions & 5 deletions examples/trio-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, stream):
self.conn = h11.Connection(h11.SERVER)
# Our Server: header
self.ident = " ".join(
["h11-example-trio-server/{}".format(h11.__version__), h11.PRODUCT_ID]
[f"h11-example-trio-server/{h11.__version__}", h11.PRODUCT_ID]
).encode("ascii")
# A unique id for this connection, to include in debugging output
# (useful for understanding what's going on if there are multiple
Expand Down Expand Up @@ -206,7 +206,7 @@ def basic_headers(self):

def info(self, *args):
# Little debugging method
print("{}:".format(self._obj_id), *args)
print(f"{self._obj_id}:", *args)


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

if wrapper.conn.our_state is h11.MUST_CLOSE:
Expand All @@ -268,7 +268,7 @@ async def http_serve(stream):
states = wrapper.conn.states
wrapper.info("unexpected state", states, "-- bailing out")
await maybe_send_error_response(
wrapper, RuntimeError("unexpected state {}".format(states))
wrapper, RuntimeError(f"unexpected state {states}")
)
await wrapper.shutdown_and_clean_up()
return
Expand Down Expand Up @@ -343,7 +343,7 @@ async def send_echo_response(wrapper, request):


async def serve(port):
print("listening on http://localhost:{}".format(port))
print(f"listening on http://localhost:{port}")
try:
await trio.serve_tcp(http_serve, port)
except KeyboardInterrupt:
Expand Down
2 changes: 1 addition & 1 deletion h11/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(
self._max_incomplete_event_size = max_incomplete_event_size
# State and role tracking
if our_role not in (CLIENT, SERVER):
raise ValueError("expected CLIENT or SERVER, not {!r}".format(our_role))
raise ValueError(f"expected CLIENT or SERVER, not {our_role!r}")
self.our_role = our_role
self.their_role: Type[Sentinel]
if our_role is CLIENT:
Expand Down
2 changes: 1 addition & 1 deletion h11/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _fire_state_triggered_transitions(self) -> None:
def start_next_cycle(self) -> None:
if self.states != {CLIENT: DONE, SERVER: DONE}:
raise LocalProtocolError(
"not in a reusable state. self.states={}".format(self.states)
f"not in a reusable state. self.states={self.states}"
)
# Can't reach DONE/DONE with any of these active, but still, let's be
# sure.
Expand Down
2 changes: 1 addition & 1 deletion h11/tests/test_against_stdlib_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def handle(self) -> None:
def test_h11_as_server() -> None:
with socket_server(H11RequestHandler) as httpd:
host, port = httpd.server_address
url = "http://{}:{}/some-path".format(host, port)
url = f"http://{host}:{port}/some-path"
with closing(urlopen(url)) as f:
assert f.getcode() == 200
data = f.read()
Expand Down
2 changes: 1 addition & 1 deletion h11/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def setup(
) -> Tuple[Connection, Optional[List[bytes]]]:
c = Connection(SERVER)
receive_and_get(
c, "GET / HTTP/{}\r\nHost: a\r\n\r\n".format(http_version).encode("ascii")
c, f"GET / HTTP/{http_version}\r\nHost: a\r\n\r\n".encode("ascii")
)
headers = []
if header:
Expand Down

0 comments on commit a2c6894

Please sign in to comment.