From: Daniele Varrazzo Date: Thu, 31 Dec 2020 03:53:19 +0000 (+0100) Subject: Global replace of src -> cls params and attribs X-Git-Tag: 3.0.dev0~213 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a13302093c1c2b587283f23d00f04ceb70fb27a;p=thirdparty%2Fpsycopg.git Global replace of src -> cls params and attribs --- diff --git a/docs/adaptation.rst b/docs/adaptation.rst index 54f7be1d9..299e4bcdf 100644 --- a/docs/adaptation.rst +++ b/docs/adaptation.rst @@ -106,7 +106,7 @@ Objects involved in types adaptation :members: -.. autoclass:: Dumper(src, context=None) +.. autoclass:: Dumper(cls, context=None) This is an abstract base class: subclasses *must* implement the `dump()` method and specify the `format`. @@ -115,8 +115,8 @@ Objects involved in types adaptation from the context, but this may fail in some contexts and may require a cast. - :param src: The type that will be managed by this dumper. - :type src: type + :param cls: The type that will be managed by this dumper. + :type cls: type :param context: The context where the transformation is performed. If not specified the conversion might be inaccurate, for instance it will not be possible to know the connection encoding or the server date format. @@ -157,18 +157,18 @@ Objects involved in types adaptation Document how to find type OIDs in a database. - .. automethod:: register(src, context=None) + .. automethod:: register(cls, context=None) You should call this method on the `Dumper` subclass you create, - passing the Python type you want to dump as *src*. + passing the Python type you want to dump as *cls*. - :param src: The type to manage. - :type src: `!type` or `!str` + :param cls: The type to manage. + :type cls: `!type` or `!str` :param context: Where the dumper should be used. If `!None` the dumper will be used globally. :type context: `~psycopg3.Connection`, `~psycopg3.Cursor`, or `Transformer` - If *src* is specified as string it will be lazy-loaded, so that it + If *cls* is specified as string it will be lazy-loaded, so that it will be possible to register it without importing it before. In this case it should be the fully qualified name of the object (e.g. ``"uuid.UUID"``). diff --git a/psycopg3/psycopg3/types/composite.py b/psycopg3/psycopg3/types/composite.py index 4d727c96d..46439dc37 100644 --- a/psycopg3/psycopg3/types/composite.py +++ b/psycopg3/psycopg3/types/composite.py @@ -147,8 +147,8 @@ class SequenceDumper(Dumper): format = Format.TEXT - def __init__(self, src: type, context: Optional[AdaptContext] = None): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + super().__init__(cls, context) self._tx = Transformer(context) def _dump_sequence( diff --git a/psycopg3/psycopg3/types/date.py b/psycopg3/psycopg3/types/date.py index 2d91bc59e..2555abd31 100644 --- a/psycopg3/psycopg3/types/date.py +++ b/psycopg3/psycopg3/types/date.py @@ -55,8 +55,8 @@ class TimeDeltaDumper(Dumper): format = Format.TEXT _oid = builtins["interval"].oid - def __init__(self, src: type, context: Optional[AdaptContext] = None): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + super().__init__(cls, context) if self.connection: if ( self.connection.pgconn.parameter_status(b"IntervalStyle") diff --git a/psycopg3/psycopg3/types/text.py b/psycopg3/psycopg3/types/text.py index a36eafee7..a4306cddf 100644 --- a/psycopg3/psycopg3/types/text.py +++ b/psycopg3/psycopg3/types/text.py @@ -20,8 +20,8 @@ class _StringDumper(Dumper): _encoding = "utf-8" - def __init__(self, src: type, context: Optional[AdaptContext] = None): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + super().__init__(cls, context) conn = self.connection if conn: @@ -87,8 +87,8 @@ class BytesDumper(Dumper): format = Format.TEXT _oid = builtins["bytea"].oid - def __init__(self, src: type, context: Optional[AdaptContext] = None): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + super().__init__(cls, context) self._esc = Escaping( self.connection.pgconn if self.connection else None ) diff --git a/psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx b/psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx index aa6d30bfb..68c7e5480 100644 --- a/psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx +++ b/psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx @@ -30,13 +30,13 @@ logger = logging.getLogger("psycopg3.adapt") cdef class CDumper: - cdef object src + cdef object cls cdef public libpq.Oid oid cdef readonly object connection cdef pq.PGconn _pgconn - def __init__(self, src: type, context: Optional[AdaptContext] = None): - self.src = src + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + self.cls = cls self.connection = context.connection if context is not None else None self._pgconn = ( self.connection.pgconn if self.connection is not None else None @@ -91,7 +91,7 @@ cdef class CDumper: @classmethod def register( cls, - src: Union[type, str], + cls: Union[type, str], context: Optional[AdaptContext] = None, int format = Format.TEXT, ) -> None: @@ -100,7 +100,7 @@ cdef class CDumper: else: from psycopg3.adapt import global_adapters as adapters - adapters.register_dumper(src, cls) + adapters.register_dumper(cls, cls) cdef class CLoader: diff --git a/psycopg3_c/psycopg3_c/types/numeric.pyx b/psycopg3_c/psycopg3_c/types/numeric.pyx index 67a947653..b33953bdf 100644 --- a/psycopg3_c/psycopg3_c/types/numeric.pyx +++ b/psycopg3_c/psycopg3_c/types/numeric.pyx @@ -26,8 +26,8 @@ cdef class IntDumper(CDumper): def __cinit__(self): self.oid = oids.INT8_OID - def __init__(self, src: type, context: Optional[AdaptContext] = None): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + super().__init__(cls, context) def dump(self, obj) -> bytes: cdef char buf[22] diff --git a/psycopg3_c/psycopg3_c/types/text.pyx b/psycopg3_c/psycopg3_c/types/text.pyx index a6a2701d2..bebe144bf 100644 --- a/psycopg3_c/psycopg3_c/types/text.pyx +++ b/psycopg3_c/psycopg3_c/types/text.pyx @@ -16,8 +16,8 @@ cdef class _StringDumper(CDumper): cdef char *encoding cdef bytes _bytes_encoding # needed to keep `encoding` alive - def __init__(self, src: type, context: Optional[AdaptContext]): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext]): + super().__init__(cls, context) self.is_utf8 = 0 self.encoding = "utf-8" @@ -116,8 +116,8 @@ cdef class BytesDumper(CDumper): def __cinit__(self): self.oid = oids.BYTEA_OID - def __init__(self, src: type, context: Optional[AdaptContext] = None): - super().__init__(src, context) + def __init__(self, cls: type, context: Optional[AdaptContext] = None): + super().__init__(cls, context) self.esc = Escaping(self._pgconn) def dump(self, obj) -> memoryview: