From 5b6a1a98903830ac563f936ccbe1fe30d88ec77c Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Sat, 28 Mar 2020 11:04:44 +0100 Subject: [PATCH] Fix typo in resultproxy.c and test compatibility with python 3.5 - Fix typo in resultproxy.c that would error on windows. - add -Wundef to C flags when linux is detected so that undefined symbols emit a warning - a few adjustments for tests to succeed on python 3.5 - note minimum version still documented here as 3.4 but this should move to at least 3.5 if not 3.6 for SQLAlchemy 1.4 Change-Id: Ia93ee1cb5c52e51e72eb0a24c100421c5157d04b --- lib/sqlalchemy/cextension/resultproxy.c | 4 ++-- lib/sqlalchemy/testing/util.py | 3 ++- setup.py | 24 ++++++++++++++++-------- test/base/test_utils.py | 2 ++ test/orm/test_unitofwork.py | 20 +++++++++++++++----- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index f622e6a288..b105038bce 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -21,7 +21,7 @@ typedef Py_ssize_t (*lenfunc)(PyObject *); typedef intargfunc ssizeargfunc; #endif -#if PY_MAJOR_VERSON < 3 +#if PY_MAJOR_VERSION < 3 // new typedef in Python 3 typedef long Py_hash_t; @@ -359,7 +359,7 @@ BaseRow_subscript_impl(BaseRow *self, PyObject *key, int asmapping) /* -1 can be either the actual value, or an error flag. */ return NULL; if (index < 0) - index += BaseRow_length(self); + index += (long)BaseRow_length(self); return BaseRow_getitem(self, index); } else if (PySlice_Check(key)) { values = PyObject_GetItem(self->row, key); diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py index c52dc4a19b..586974f11b 100644 --- a/lib/sqlalchemy/testing/util.py +++ b/lib/sqlalchemy/testing/util.py @@ -17,6 +17,7 @@ from ..util import defaultdict from ..util import has_refcount_gc from ..util import inspect_getfullargspec from ..util import py2k +from ..util import py36 if not has_refcount_gc: @@ -53,7 +54,7 @@ def picklers(): yield pickle_.loads, lambda d: pickle_.dumps(d, protocol) -if py2k: +if py2k or not py36: def random_choices(population, k=1): pop = list(population) diff --git a/setup.py b/setup.py index cb117d7875..e77c617b42 100644 --- a/setup.py +++ b/setup.py @@ -20,27 +20,35 @@ if sys.version_info < (2, 7): cpython = platform.python_implementation() == "CPython" +ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) +if sys.platform == "win32": + # Work around issue https://github.com/pypa/setuptools/issues/1902 + ext_errors += (IOError, TypeError) + extra_compile_args = [] +elif sys.platform == "linux": + # warn for undefined symbols in .c files + extra_compile_args = ["-Wundef"] +else: + extra_compile_args = [] + ext_modules = [ Extension( "sqlalchemy.cprocessors", sources=["lib/sqlalchemy/cextension/processors.c"], + extra_compile_args=extra_compile_args, ), Extension( "sqlalchemy.cresultproxy", sources=["lib/sqlalchemy/cextension/resultproxy.c"], + extra_compile_args=extra_compile_args, ), Extension( - "sqlalchemy.cutils", sources=["lib/sqlalchemy/cextension/utils.c"] + "sqlalchemy.cutils", + sources=["lib/sqlalchemy/cextension/utils.c"], + extra_compile_args=extra_compile_args, ), ] -ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) -if sys.platform == "win32": - # 2.6's distutils.msvc9compiler can raise an IOError when failing to - # find the compiler - # for TypeError, see https://github.com/pypa/setuptools/issues/1902 - ext_errors += (IOError, TypeError) - class BuildFailed(Exception): def __init__(self): diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 662baa38a4..246199861f 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -3185,6 +3185,8 @@ class TimezoneTest(fixtures.TestBase): ), ) def test_tzname(self, td, expected): + if expected == "UTC" and util.py3k and not util.py36: + expected += "+00:00" eq_(timezone(td).tzname(None), expected) def test_utcoffset(self): diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index 2813c1e7e0..3a1594a613 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -3472,12 +3472,22 @@ class EnsurePKSortableTest(fixtures.MappedTest): a.data = "bar" b.data = "foo" if sa.util.py3k: + if sa.util.py36: + message = ( + r"Could not sort objects by primary key; primary key " + r"values must be sortable in Python \(was: '<' not " + r"supported between instances of 'MyNotSortableEnum'" + r" and 'MyNotSortableEnum'\)" + ) + else: + message = ( + r"Could not sort objects by primary key; primary key " + r"values must be sortable in Python \(was: unorderable " + r"types: MyNotSortableEnum\(\) < MyNotSortableEnum\(\)\)" + ) + assert_raises_message( - sa.exc.InvalidRequestError, - r"Could not sort objects by primary key; primary key values " - r"must be sortable in Python \(was: '<' not supported between " - r"instances of 'MyNotSortableEnum' and 'MyNotSortableEnum'\)", - s.flush, + sa.exc.InvalidRequestError, message, s.flush, ) else: s.flush() -- 2.47.3