From: Daniele Varrazzo Date: Thu, 23 Apr 2020 04:29:35 +0000 (+1200) Subject: Don't import Python API function from the main cpython package X-Git-Tag: 3.0.dev0~543 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5647fb04dc6eb3e46e2a7bde490feea5be11f2c1;p=thirdparty%2Fpsycopg.git Don't import Python API function from the main cpython package Importing from there seems deprecated. [skip ci] --- diff --git a/psycopg3/transform.pyx b/psycopg3/transform.pyx index 24c87f840..f59153b80 100644 --- a/psycopg3/transform.pyx +++ b/psycopg3/transform.pyx @@ -1,6 +1,8 @@ from libc.string cimport memset -from cpython.ref cimport PyObject +from cpython.object cimport PyObject +from cpython.ref cimport Py_INCREF from cpython.mem cimport PyMem_Malloc, PyMem_Free +from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM import codecs from typing import Any, Dict, Iterable, List, Optional, Tuple @@ -256,13 +258,13 @@ cdef class Transformer: cdef int col cdef int length cdef const char *val - rv = cpython.PyTuple_New(self._nfields) + rv = PyTuple_New(self._nfields) for col in range(self._nfields): length = libpq.PQgetlength(res, crow, col) if length == 0: if libpq.PQgetisnull(res, crow, col): - cpython.Py_INCREF(None) - cpython.PyTuple_SET_ITEM(rv, col, None) + Py_INCREF(None) + PyTuple_SET_ITEM(rv, col, None) continue val = libpq.PQgetvalue(res, crow, col) @@ -273,8 +275,8 @@ cdef class Transformer: # TODO: no copy pyval = (loader.pyloader)(val[:length]) - cpython.Py_INCREF(pyval) - cpython.PyTuple_SET_ITEM(rv, col, pyval) + Py_INCREF(pyval) + PyTuple_SET_ITEM(rv, col, pyval) return rv diff --git a/psycopg3/types/numeric.pyx b/psycopg3/types/numeric.pyx index eb1b165a0..10a1ff8ba 100644 --- a/psycopg3/types/numeric.pyx +++ b/psycopg3/types/numeric.pyx @@ -1,19 +1,21 @@ -cimport cpython +from cpython.long cimport ( + PyLong_FromLong, PyLong_FromLongLong, PyLong_FromUnsignedLong) + cdef object load_int_text(const char *data, size_t length, void *context): return int(data) cdef object load_int2_binary(const char *data, size_t length, void *context): - return cpython.PyLong_FromLong(unpack_int16(data, 2)) + return PyLong_FromLong(unpack_int16(data, 2)) cdef object load_int4_binary(const char *data, size_t length, void *context): - return cpython.PyLong_FromLong(unpack_int32(data, 4)) + return PyLong_FromLong(unpack_int32(data, 4)) cdef object load_int8_binary(const char *data, size_t length, void *context): - return cpython.PyLong_FromLongLong(unpack_int64(data, 8)) + return PyLong_FromLongLong(unpack_int64(data, 8)) cdef object load_oid_binary(const char *data, size_t length, void *context): - return cpython.PyLong_FromUnsignedLong(unpack_uint32(data, 4)) + return PyLong_FromUnsignedLong(unpack_uint32(data, 4)) cdef object load_bool_binary(const char *data, size_t length, void *context): if data[0]: diff --git a/psycopg3/types/text.pyx b/psycopg3/types/text.pyx index 52143b4fb..1fb2fb2b4 100644 --- a/psycopg3/types/text.pyx +++ b/psycopg3/types/text.pyx @@ -1,10 +1,10 @@ -cimport cpython +from cpython.unicode cimport PyUnicode_DecodeUTF8 cdef object load_text_binary(const char *data, size_t length, void *context): # TODO: codec - return cpython.PyUnicode_DecodeUTF8(data, length, NULL) + return PyUnicode_DecodeUTF8(data, length, NULL) cdef object load_unknown_binary(const char *data, size_t length, void *context): # TODO: codec - return cpython.PyUnicode_DecodeUTF8(data, length, NULL) + return PyUnicode_DecodeUTF8(data, length, NULL)