]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
docs: mention LiteralString and related changes in docs
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 27 Jun 2022 21:55:57 +0000 (22:55 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 3 Jul 2022 02:52:59 +0000 (03:52 +0100)
docs/api/connections.rst
docs/api/cursors.rst
docs/api/sql.rst
docs/basic/params.rst
docs/news.rst

index b1858fb1dda8b2f21c55bcc12bc22d60cf2d8278..93ea5218dd3100e4d2db3e33d5bc52e387fe1681 100644 (file)
@@ -143,7 +143,7 @@ The `!Connection` class
     .. automethod:: execute
 
         :param query: The query to execute.
-        :type query: `!str`, `!bytes`, or `sql.Composable`
+        :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
         :param params: The parameters to pass to the query, if any.
         :type params: Sequence or Mapping
         :param prepare: Force (`!True`) or disallow (`!False`) preparation of
index a3be8b6037043bb09474d07617018a530efc0a31..f0f5df75682b88d76d4a8a0248fc99f67a0b45a5 100644 (file)
@@ -61,7 +61,7 @@ The `!Cursor` class
     .. automethod:: execute
 
         :param query: The query to execute.
-        :type query: `!str`, `!bytes`, or `sql.Composable`
+        :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
         :param params: The parameters to pass to the query, if any.
         :type params: Sequence or Mapping
         :param prepare: Force (`!True`) or disallow (`!False`) preparation of
@@ -77,10 +77,18 @@ The `!Cursor` class
         See :ref:`query-parameters` for all the details about executing
         queries.
 
+        .. versionchanged:: 3.1
+
+            The `query` argument must be a `~typing.StringLiteral`. If you
+            need to compose a query dynamically, please use `sql.SQL` and
+            related objects.
+
+            See :pep:`675` for details.
+
     .. automethod:: executemany
 
         :param query: The query to execute
-        :type query: `!str`, `!bytes`, or `sql.Composable`
+        :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
         :param params_seq: The parameters to pass to the query
         :type params_seq: Sequence of Sequences or Mappings
         :param returning: If `!True`, fetch the results of the queries executed
@@ -109,7 +117,7 @@ The `!Cursor` class
     .. automethod:: copy
 
         :param statement: The copy operation to execute
-        :type statement: `!str`, `!bytes`, or `sql.Composable`
+        :type statement: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
         :param params: The parameters to pass to the statement, if any.
         :type params: Sequence or Mapping
 
@@ -261,7 +269,7 @@ The `!ClientCursor` class
     .. automethod:: mogrify
 
         :param query: The query to execute.
-        :type query: `!str`, `!bytes`, or `sql.Composable`
+        :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
         :param params: The parameters to pass to the query, if any.
         :type params: Sequence or Mapping
 
@@ -315,7 +323,7 @@ The `!ServerCursor` class
     .. automethod:: execute
 
         :param query: The query to execute.
-        :type query: `!str`, `!bytes`, or `sql.Composable`
+        :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
         :param params: The parameters to pass to the query, if any.
         :type params: Sequence or Mapping
         :param binary: Specify whether the server shoul return data in binary
index 63906f8739e8b6628083e990383602be6d57f807..6959fee4dba87df92ec7f2c74a0fe9f236f21a16 100644 (file)
@@ -114,6 +114,11 @@ The `!sql` objects are in the following inheritance hierarchy:
 
 .. autoclass:: SQL
 
+    .. versionchanged:: 3.1
+
+        The input object should be a `~typing.LiteralString`. See :pep:`675`
+        for details.
+
     .. automethod:: format
 
     .. automethod:: join
index 5033e9a91d676424e09ff32efc31b099378d977a..27d80431013dc51b44a5d728058caa38553b1216 100644 (file)
@@ -186,6 +186,21 @@ argument of the `Cursor.execute()` method::
     at :ref:`how Psycopg converts data types <types-adaptation>`.
 
 
+Using `LiteralString` in queries
+--------------------------------
+
+The `~Cursor.execute()` method and similar should only receive a literal
+string as input, according to :pep:`675`.
+
+If you need to compose a query dynamically you should use `sql.SQL` and
+similar methods.
+
+At the time of writing the feature is experimental and only checked by the
+Pyre_ checker.
+
+.. _Pyre: https://pyre-check.org/
+
+
 .. index::
     pair: Binary; Parameters
 
index e5f75ef92134f735b9be2f40496142e8b11d39c1..c6d00304eb017d5226a12cbe31fa201313934386 100644 (file)
@@ -28,6 +28,8 @@ Psycopg 3.1 (unreleased)
 - Add ``prepare_threshold`` parameter to `Connection` init (:ticket:`#200`).
 - Add ``cursor_factory`` parameter to `Connection` init.
 - Add `Error.pgconn` and `Error.pgresult` attributes (:ticket:`#242`).
+- Restrict queries to be `~typing.LiteralString` as per :pep:`675`
+  (:ticket:`#323`).
 - Add explicit type cast to values converted by `sql.Literal` (:ticket:`#205`).
 - Drop support for Python 3.6.