PEP 675: Clarify Motivation query examples are abridged (#2854)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
parent
a3310aeeff
commit
dc44249a14
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue