]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Consistent 'src' name for the first argument of the adapters
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 4 Apr 2020 15:14:08 +0000 (03:14 +1200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 4 Apr 2020 15:14:08 +0000 (03:14 +1200)
'cls' is messy when it comes to class methods.

psycopg3/adapt.py
psycopg3/types/array.py
psycopg3/types/text.py

index bfe24251ccf78b8cdb4528729a40569d60237b52..ab459a48d006bc2b5d18c1ce91b1893963e380ed 100644 (file)
@@ -239,24 +239,24 @@ class Transformer:
         if obj is None:
             return None, TEXT_OID
 
-        cls = type(obj)
-        func = self.get_adapt_function(cls, fmt)
+        src = type(obj)
+        func = self.get_adapt_function(src, fmt)
         return func(obj)
 
-    def get_adapt_function(self, cls: type, fmt: Format) -> AdapterFunc:
+    def get_adapt_function(self, src: type, fmt: Format) -> AdapterFunc:
         try:
-            return self._adapt_funcs[cls, fmt]
+            return self._adapt_funcs[src, fmt]
         except KeyError:
             pass
 
-        adapter = self.lookup_adapter(cls, fmt)
+        adapter = self.lookup_adapter(src, fmt)
         if isinstance(adapter, type):
-            return adapter(cls, self.connection).adapt
+            return adapter(src, self.connection).adapt
         else:
             return adapter
 
-    def lookup_adapter(self, cls: type, fmt: Format) -> AdapterType:
-        key = (cls, fmt)
+    def lookup_adapter(self, src: type, fmt: Format) -> AdapterType:
+        key = (src, fmt)
 
         cur = self.cursor
         if cur is not None and key in cur.adapters:
@@ -270,7 +270,7 @@ class Transformer:
             return Adapter.globals[key]
 
         raise e.ProgrammingError(
-            f"cannot adapt type {cls} to format {Format(fmt).name}"
+            f"cannot adapt type {src} to format {Format(fmt).name}"
         )
 
     def cast_row(self, result: PGresult, n: int) -> Generator[Any, None, None]:
index 8b85c68ad6541ce8cb723eb0bcd70a2ce2acab9e..e4a51bd1d090ce0d88cc04fac1d76375b9495580 100644 (file)
@@ -57,8 +57,8 @@ def escape_item(item: Optional[bytes]) -> bytes:
 
 @Adapter.text(list)
 class ListAdapter(Adapter):
-    def __init__(self, cls: type, context: AdaptContext = None):
-        super().__init__(cls, context)
+    def __init__(self, src: type, context: AdaptContext = None):
+        super().__init__(src, context)
         self.tx = Transformer(context)
 
     def adapt(self, obj: List[Any]) -> bytes:
index 91fdbd3056d1a0e97d9858dc3181faa0f63ecc4a..f9820b4f3fdf532f4f28458c90a38898f31266c6 100644 (file)
@@ -20,8 +20,8 @@ BYTEA_OID = builtins["bytea"].oid
 @Adapter.text(str)
 @Adapter.binary(str)
 class StringAdapter(Adapter):
-    def __init__(self, cls: type, context: AdaptContext):
-        super().__init__(cls, context)
+    def __init__(self, src: type, context: AdaptContext):
+        super().__init__(src, context)
 
         self._encode: EncodeFunc
         if self.connection is not None:
@@ -65,8 +65,8 @@ class StringCaster(TypeCaster):
 
 @Adapter.text(bytes)
 class BytesAdapter(Adapter):
-    def __init__(self, cls: type, context: AdaptContext = None):
-        super().__init__(cls, context)
+    def __init__(self, src: type, context: AdaptContext = None):
+        super().__init__(src, context)
         self.esc = Escaping(
             self.connection.pgconn if self.connection is not None else None
         )