mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 02:13:44 +03:00
Merge branch 'fix-591'
This commit is contained in:
commit
483901ea7b
1
NEWS
1
NEWS
|
@ -18,6 +18,7 @@ New features:
|
|||
structure (:ticket:`#782`).
|
||||
- `~psycopg2.sql.Identifier` can represent qualified names in SQL composition
|
||||
(:ticket:`#732`).
|
||||
- Fixed adaptation of numeric subclasses such as `IntEnum` (:ticket:`591`).
|
||||
- `!str()` on `~psycopg2.extras.Range` produces a human-readable representation
|
||||
(:ticket:`#773`).
|
||||
- `~psycopg2.extras.DictCursor` and `~psycopg2.extras.RealDictCursor` rows
|
||||
|
|
|
@ -35,8 +35,27 @@
|
|||
static PyObject *
|
||||
pint_getquoted(pintObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *res;
|
||||
if (!(res = PyObject_Str(self->wrapped))) {
|
||||
PyObject *res = NULL;
|
||||
|
||||
/* Convert subclass to int to handle IntEnum and other subclasses
|
||||
* whose str() is not the number. */
|
||||
if (PyLong_CheckExact(self->wrapped)
|
||||
#if PY_MAJOR_VERSION < 2
|
||||
|| PyInt_CheckExact(self->wrapped)
|
||||
#endif
|
||||
) {
|
||||
res = PyObject_Str(self->wrapped);
|
||||
} else {
|
||||
PyObject *tmp;
|
||||
if (!(tmp = PyObject_CallFunctionObjArgs(
|
||||
(PyObject *)&PyLong_Type, self->wrapped, NULL))) {
|
||||
goto exit;
|
||||
}
|
||||
res = PyObject_Str(tmp);
|
||||
Py_DECREF(tmp);
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
|
@ -382,6 +382,18 @@ class TypesBasicTests(ConnectingTestCase):
|
|||
a = self.execute("select '{10:20:30:40:50:60}'::macaddr[]")
|
||||
self.assertEqual(a, ['10:20:30:40:50:60'])
|
||||
|
||||
@testutils.skip_before_python(3, 4)
|
||||
def testIntEnum(self):
|
||||
from enum import IntEnum
|
||||
|
||||
class Color(IntEnum):
|
||||
RED = 1
|
||||
GREEN = 2
|
||||
BLUE = 4
|
||||
|
||||
a = self.execute("select %s", (Color.GREEN,))
|
||||
self.assertEqual(a, Color.GREEN)
|
||||
|
||||
|
||||
class AdaptSubclassTest(unittest.TestCase):
|
||||
def test_adapt_subtype(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user