]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Bypass call to _get_optimised if using the Python implementation
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 2 May 2021 00:10:41 +0000 (02:10 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 2 May 2021 00:10:41 +0000 (02:10 +0200)
psycopg3/psycopg3/adapt.py

index a5501fa4812ab0d7ff17f8ec16302288406740f3..43f2c6c1b8561fec3ee89373be44c3f45bfe6dda 100644 (file)
@@ -186,7 +186,9 @@ class AdaptersMap(AdaptContext):
                 f"dumpers should be registered on classes, got {cls} instead"
             )
 
-        dumper = self._get_optimised(dumper)
+        if pq.__impl__ != "python":
+            dumper = self._get_optimised(dumper)
+
         # Register the dumper both as its format and as default
         for fmt in (Format.from_pq(dumper.format), Format.AUTO):
             if not self._own_dumpers[fmt]:
@@ -208,7 +210,9 @@ class AdaptersMap(AdaptContext):
                 f"loaders should be registered on oid, got {oid} instead"
             )
 
-        loader = self._get_optimised(loader)
+        if pq.__impl__ != "python":
+            loader = self._get_optimised(loader)
+
         fmt = loader.format
         if not self._own_loaders[fmt]:
             self._loaders[fmt] = self._loaders[fmt].copy()
@@ -267,15 +271,14 @@ class AdaptersMap(AdaptContext):
 
         # Check if the class comes from psycopg3.types and there is a class
         # with the same name in psycopg3_c._psycopg3.
-        if pq.__impl__ == "c":
-            from psycopg3 import types
-            from psycopg3_c import _psycopg3
-
-            if cls.__module__.startswith(types.__name__):
-                new = cast(Type[RV], getattr(_psycopg3, cls.__name__, None))
-                if new:
-                    self._optimised[cls] = new
-                    return new
+        from psycopg3 import types
+        from psycopg3_c import _psycopg3
+
+        if cls.__module__.startswith(types.__name__):
+            new = cast(Type[RV], getattr(_psycopg3, cls.__name__, None))
+            if new:
+                self._optimised[cls] = new
+                return new
 
         self._optimised[cls] = cls
         return cls