From dc44249a14d333d81923cb38a8b7ae791dcb2fbd Mon Sep 17 00:00:00 2001 From: Eclips4 <80244920+Eclips4@users.noreply.github.com> Date: Sun, 30 Oct 2022 16:29:39 +0300 Subject: [PATCH] PEP 675: Clarify Motivation query examples are abridged (#2854) Co-authored-by: C.A.M. Gerlach --- pep-0675.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pep-0675.rst b/pep-0675.rst index 175fba9b0..b42808891 100644 --- a/pep-0675.rst +++ b/pep-0675.rst @@ -42,6 +42,7 @@ insert it into a predefined SQL query: def query_user(conn: Connection, user_id: str) -> User: query = f"SELECT * FROM data WHERE user_id = {user_id}" conn.execute(query) + ... # Transform data to a User object and return it query_user(conn, "user123") # OK. @@ -69,7 +70,7 @@ original function would be written safely as a query with parameters: def query_user(conn: Connection, user_id: str) -> User: query = "SELECT * FROM data WHERE user_id = ?" conn.execute(query, (user_id,)) - + ... The problem is that there is no way to enforce this discipline. sqlite3's own `documentation @@ -140,8 +141,8 @@ from a format string using ``user_id``, and cannot be passed to def query_user(conn: Connection, user_id: str) -> User: query = f"SELECT * FROM data WHERE user_id = {user_id}" - conn.execute(query) - # Error: Expected LiteralString, got str. + conn.execute(query) # Error: Expected LiteralString, got str. + ... The method remains flexible enough to allow our more complicated example: