]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix(c): don't try to mutate Cython type
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 2 Aug 2023 00:14:04 +0000 (01:14 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 5 Aug 2023 14:21:30 +0000 (15:21 +0100)
These types are now marked immutable. Use a module variable instead.

psycopg_c/psycopg_c/types/numeric.pyx

index 941785b01d43ee001f37c4399935232daade3e96..de76a236c4b39cbaa579a8ea75e6f3800782748d 100644 (file)
@@ -498,19 +498,22 @@ cdef class DecimalBinaryDumper(CDumper):
         return dump_decimal_to_numeric_binary(obj, rv, offset)
 
 
+_int_classes = None
+
+
 cdef class _MixedNumericDumper(CDumper):
 
-    int_classes = None
     oid = oids.NUMERIC_OID
 
     def __cinit__(self, cls, context: Optional[AdaptContext] = None):
-        if _MixedNumericDumper.int_classes is None:
+        global _int_classes
+
+        if _int_classes is None:
             if "numpy" in sys.modules:
                 import numpy
-
-                _MixedNumericDumper.int_classes = (int, numpy.integer)
+                _int_classes = (int, numpy.integer)
             else:
-                _MixedNumericDumper.int_classes = int
+                _int_classes = int
 
 
 @cython.final
@@ -523,7 +526,7 @@ cdef class NumericDumper(_MixedNumericDumper):
             return dump_int_to_text(obj, rv, offset)
         elif isinstance(obj, Decimal):
             return dump_decimal_to_text(obj, rv, offset)
-        elif isinstance(obj, self.int_classes):
+        elif isinstance(obj, _int_classes):
             return dump_int_to_text(obj, rv, offset)
         else:
             raise TypeError(
@@ -541,7 +544,7 @@ cdef class NumericBinaryDumper(_MixedNumericDumper):
             return dump_int_to_numeric_binary(obj, rv, offset)
         elif isinstance(obj, Decimal):
             return dump_decimal_to_numeric_binary(obj, rv, offset)
-        elif isinstance(obj, self.int_classes):
+        elif isinstance(obj, _int_classes):
             return dump_int_to_numeric_binary(int(obj), rv, offset)
         else:
             raise TypeError(