]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Use slots on PostgresQuery object
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 30 Dec 2020 03:03:06 +0000 (04:03 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 8 Jan 2021 01:26:53 +0000 (02:26 +0100)
psycopg3/psycopg3/_queries.py

index 2828471bb602effd6e4559d77103c7a73ee3a79e..55d234fac889bfb0cc73af57a0457d67394cdc08 100644 (file)
@@ -30,19 +30,25 @@ class PostgresQuery:
     Helper to convert a Python query and parameters into Postgres format.
     """
 
-    _unknown_oid = INVALID_OID
-
-    _parts: List[QueryPart]
-    _query = b""
-    _encoding: str = "utf-8"
-    params: Optional[List[Optional[bytes]]] = None
-    # these are tuples so they can be used as keys e.g. in prepared stmts
-    types: Tuple[int, ...] = ()
-    formats: Optional[List[Format]] = None
-    _order: Optional[List[str]] = None
+    __slots__ = """
+        params types formats
+        _tx _unknown_oid _parts query _encoding _order
+        """.split()
 
     def __init__(self, transformer: "Transformer"):
         self._tx = transformer
+
+        self.params: Optional[List[Optional[bytes]]] = None
+        # these are tuples so they can be used as keys e.g. in prepared stmts
+        self.types: Tuple[int, ...] = ()
+        self.formats: Optional[List[Format]] = None
+
+        self._unknown_oid = INVALID_OID
+        self._parts: List[QueryPart]
+        self.query = b""
+        self._encoding = "utf-8"
+        self._order: Optional[List[str]] = None
+
         conn = transformer.connection
         if conn:
             self._encoding = conn.client_encoding