From: Daniele Varrazzo Date: Sat, 4 Apr 2020 15:14:08 +0000 (+1200) Subject: Consistent 'src' name for the first argument of the adapters X-Git-Tag: 3.0.dev0~610 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05699afe460028b5078fed4d688a903bed654f0e;p=thirdparty%2Fpsycopg.git Consistent 'src' name for the first argument of the adapters 'cls' is messy when it comes to class methods. --- diff --git a/psycopg3/adapt.py b/psycopg3/adapt.py index bfe24251c..ab459a48d 100644 --- a/psycopg3/adapt.py +++ b/psycopg3/adapt.py @@ -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]: diff --git a/psycopg3/types/array.py b/psycopg3/types/array.py index 8b85c68ad..e4a51bd1d 100644 --- a/psycopg3/types/array.py +++ b/psycopg3/types/array.py @@ -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: diff --git a/psycopg3/types/text.py b/psycopg3/types/text.py index 91fdbd305..f9820b4f3 100644 --- a/psycopg3/types/text.py +++ b/psycopg3/types/text.py @@ -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 )