]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
First round of removal of python 2
authorFederico Caselli <cfederico87@gmail.com>
Sat, 30 Oct 2021 20:00:25 +0000 (22:00 +0200)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 1 Nov 2021 19:11:25 +0000 (15:11 -0400)
References: #4600
Change-Id: I61e35bc93fe95610ae75b31c18a3282558cd4ffe

65 files changed:
examples/dogpile_caching/environment.py
lib/sqlalchemy/dialects/mssql/information_schema.py
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/dialects/oracle/cx_oracle.py
lib/sqlalchemy/dialects/postgresql/hstore.py
lib/sqlalchemy/dialects/postgresql/psycopg2.py
lib/sqlalchemy/dialects/sqlite/pysqlite.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/engine/reflection.py
lib/sqlalchemy/engine/result.py
lib/sqlalchemy/engine/url.py
lib/sqlalchemy/ext/associationproxy.py
lib/sqlalchemy/orm/collections.py
lib/sqlalchemy/orm/evaluator.py
lib/sqlalchemy/orm/identity.py
lib/sqlalchemy/orm/instrumentation.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/operators.py
lib/sqlalchemy/sql/sqltypes.py
lib/sqlalchemy/sql/type_api.py
lib/sqlalchemy/testing/exclusions.py
lib/sqlalchemy/testing/plugin/bootstrap.py
lib/sqlalchemy/testing/plugin/pytestplugin.py
lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py [deleted file]
lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/testing/suite/test_dialect.py
lib/sqlalchemy/testing/suite/test_types.py
lib/sqlalchemy/testing/suite/test_unicode_ddl.py
lib/sqlalchemy/testing/util.py
lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/_collections.py
lib/sqlalchemy/util/compat.py
lib/sqlalchemy/util/langhelpers.py
test/aaa_profiling/test_misc.py
test/base/test_concurrency_py3k.py
test/base/test_events.py
test/base/test_tutorials.py
test/base/test_utils.py
test/dialect/mssql/test_query.py
test/dialect/mssql/test_types.py
test/dialect/oracle/test_dialect.py
test/dialect/oracle/test_types.py
test/dialect/postgresql/test_dialect.py
test/dialect/postgresql/test_types.py
test/dialect/test_sqlite.py
test/engine/test_execute.py
test/engine/test_parseconnect.py
test/engine/test_pool.py
test/ext/asyncio/test_engine_py3k.py
test/ext/asyncio/test_scoping_py3k.py
test/orm/declarative/test_basic.py
test/orm/test_collection.py
test/orm/test_dataclasses_py3k.py
test/orm/test_deprecations.py
test/orm/test_inspect.py
test/orm/test_instrumentation.py
test/orm/test_mapper.py
test/orm/test_query.py
test/orm/test_scoping.py
test/orm/test_transaction.py
test/sql/test_compare.py
test/sql/test_operators.py
test/sql/test_quote.py
test/sql/test_resultset.py

index 7f4f7e7a171f81ba89df91fa0e82269c4a48bb57..4b5a317917b9e33f63f8e5f773a01894a6b480a6 100644 (file)
@@ -4,7 +4,6 @@ bootstrap fixture data if necessary.
 """
 from hashlib import md5
 import os
-import sys
 
 from dogpile.cache.region import make_region
 
@@ -15,11 +14,6 @@ from sqlalchemy.orm import sessionmaker
 from . import caching_query
 
 
-py2k = sys.version_info < (3, 0)
-
-if py2k:
-    input = raw_input  # noqa
-
 # dogpile cache regions.  A home base for cache configurations.
 regions = {}
 
index fa0386faad353e9d701a32ee8e69e1affd9fb112..f16d3b6a0d2e871fb5d901da1ed9e1a75bcdd39b 100644 (file)
@@ -9,7 +9,6 @@ from ... import cast
 from ... import Column
 from ... import MetaData
 from ... import Table
-from ... import util
 from ...ext.compiler import compiles
 from ...sql import expression
 from ...types import Boolean
@@ -27,11 +26,6 @@ class CoerceUnicode(TypeDecorator):
     impl = Unicode
     cache_ok = True
 
-    def process_bind_param(self, value, dialect):
-        if util.py2k and isinstance(value, util.binary_type):
-            value = value.decode(dialect.encoding)
-        return value
-
     def bind_expression(self, bindvalue):
         return _cast_on_2005(bindvalue)
 
index c0bf985e56756134417bd869dd761414dcbe624b..9e62b931d9c3eb29ee6f4bd16d9f26d18e95edcd 100644 (file)
@@ -2468,8 +2468,6 @@ class OracleDialect(default.DefaultDialect):
 
         rp = connection.execute(sql.text(text), params).scalar()
         if rp:
-            if util.py2k:
-                rp = rp.decode(self.encoding)
             return rp
         else:
             return None
index 3e705dced33140df3269d43752b872cf18ddb4b7..38e8648989415ee3a8f31b3087455d132bb53852 100644 (file)
@@ -468,7 +468,6 @@ from ... import processors
 from ... import types as sqltypes
 from ... import util
 from ...engine import cursor as _cursor
-from ...util import compat
 
 
 class _OracleInteger(sqltypes.Integer):
@@ -745,24 +744,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext):
                                 " cx_oracle" % (bindparam.key, bindparam.type)
                             )
 
-                        if compat.py2k and dbtype in (
-                            cx_Oracle.CLOB,
-                            cx_Oracle.NCLOB,
-                        ):
-                            outconverter = (
-                                processors.to_unicode_processor_factory(
-                                    self.dialect.encoding,
-                                    errors=self.dialect.encoding_errors,
-                                )
-                            )
-                            self.out_parameters[name] = self.cursor.var(
-                                dbtype,
-                                outconverter=lambda value: outconverter(
-                                    value.read()
-                                ),
-                            )
-
-                        elif dbtype in (
+                        if dbtype in (
                             cx_Oracle.BLOB,
                             cx_Oracle.CLOB,
                             cx_Oracle.NCLOB,
@@ -770,18 +752,6 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext):
                             self.out_parameters[name] = self.cursor.var(
                                 dbtype, outconverter=lambda value: value.read()
                             )
-                        elif compat.py2k and isinstance(
-                            type_impl, sqltypes.Unicode
-                        ):
-                            outconverter = (
-                                processors.to_unicode_processor_factory(
-                                    self.dialect.encoding,
-                                    errors=self.dialect.encoding_errors,
-                                )
-                            )
-                            self.out_parameters[name] = self.cursor.var(
-                                dbtype, outconverter=outconverter
-                            )
                         else:
                             self.out_parameters[name] = self.cursor.var(dbtype)
                     self.parameters[0][
@@ -1182,45 +1152,23 @@ class OracleDialect_cx_oracle(OracleDialect):
                 and default_type is not cx_Oracle.CLOB
                 and default_type is not cx_Oracle.NCLOB
             ):
-                if compat.py2k:
-                    outconverter = processors.to_unicode_processor_factory(
-                        dialect.encoding, errors=dialect.encoding_errors
-                    )
-                    return cursor.var(
-                        cx_Oracle.STRING,
-                        size,
-                        cursor.arraysize,
-                        outconverter=outconverter,
-                    )
-                else:
-                    return cursor.var(
-                        util.text_type,
-                        size,
-                        cursor.arraysize,
-                        **dialect._cursor_var_unicode_kwargs
-                    )
+                return cursor.var(
+                    util.text_type,
+                    size,
+                    cursor.arraysize,
+                    **dialect._cursor_var_unicode_kwargs
+                )
 
             elif dialect.auto_convert_lobs and default_type in (
                 cx_Oracle.CLOB,
                 cx_Oracle.NCLOB,
             ):
-                if compat.py2k:
-                    outconverter = processors.to_unicode_processor_factory(
-                        dialect.encoding, errors=dialect.encoding_errors
-                    )
-                    return cursor.var(
-                        cx_Oracle.LONG_STRING,
-                        size,
-                        cursor.arraysize,
-                        outconverter=outconverter,
-                    )
-                else:
-                    return cursor.var(
-                        cx_Oracle.LONG_STRING,
-                        size,
-                        cursor.arraysize,
-                        **dialect._cursor_var_unicode_kwargs
-                    )
+                return cursor.var(
+                    cx_Oracle.LONG_STRING,
+                    size,
+                    cursor.arraysize,
+                    **dialect._cursor_var_unicode_kwargs
+                )
 
             elif dialect.auto_convert_lobs and default_type in (
                 cx_Oracle.BLOB,
index a4090f1ac5934d662091a9e092ff98b8dae388a7..85d678ef546c8856975c234e91171f71e3739d61 100644 (file)
@@ -228,42 +228,20 @@ class HSTORE(sqltypes.Indexable, sqltypes.Concatenable, sqltypes.TypeEngine):
     comparator_factory = Comparator
 
     def bind_processor(self, dialect):
-        if util.py2k:
-            encoding = dialect.encoding
-
-            def process(value):
-                if isinstance(value, dict):
-                    return _serialize_hstore(value).encode(encoding)
-                else:
-                    return value
-
-        else:
-
-            def process(value):
-                if isinstance(value, dict):
-                    return _serialize_hstore(value)
-                else:
-                    return value
+        def process(value):
+            if isinstance(value, dict):
+                return _serialize_hstore(value)
+            else:
+                return value
 
         return process
 
     def result_processor(self, dialect, coltype):
-        if util.py2k:
-            encoding = dialect.encoding
-
-            def process(value):
-                if value is not None:
-                    return _parse_hstore(value.decode(encoding))
-                else:
-                    return value
-
-        else:
-
-            def process(value):
-                if value is not None:
-                    return _parse_hstore(value)
-                else:
-                    return value
+        def process(value):
+            if value is not None:
+                return _parse_hstore(value)
+            else:
+                return value
 
         return process
 
index 7512ab9b524061910ce91800c9743006fa4d0162..162ddde9493e35a754df1d55a5b02ca9fec7005e 100644 (file)
@@ -478,7 +478,6 @@ from .base import _ColonCast
 from .base import _DECIMAL_TYPES
 from .base import _FLOAT_TYPES
 from .base import _INT_TYPES
-from .base import ENUM
 from .base import PGCompiler
 from .base import PGDialect
 from .base import PGExecutionContext
@@ -527,22 +526,6 @@ class _PGNumeric(sqltypes.Numeric):
                 )
 
 
-class _PGEnum(ENUM):
-    def result_processor(self, dialect, coltype):
-        if util.py2k and self._expect_unicode is True:
-            # for py2k, if the enum type needs unicode data (which is set up as
-            # part of the Enum() constructor based on values passed as py2k
-            # unicode objects) we have to use our own converters since
-            # psycopg2's don't work, a rare exception to the "modern DBAPIs
-            # support unicode everywhere" theme of deprecating
-            # convert_unicode=True. Use the special "force_nocheck" directive
-            # which forces unicode conversion to happen on the Python side
-            # without an isinstance() check.   in py3k psycopg2 does the right
-            # thing automatically.
-            self._expect_unicode = "force_nocheck"
-        return super(_PGEnum, self).result_processor(dialect, coltype)
-
-
 class _PGHStore(HSTORE):
     def bind_processor(self, dialect):
         if dialect._has_native_hstore:
@@ -664,16 +647,6 @@ class PGDialect_psycopg2(PGDialect):
     driver = "psycopg2"
 
     supports_statement_cache = True
-
-    if util.py2k:
-        # turn off supports_unicode_statements for Python 2. psycopg2 supports
-        # unicode statements in Py2K. But!  it does not support unicode *bound
-        # parameter names* because it uses the Python "%" operator to
-        # interpolate these into the string, and this fails.   So for Py2K, we
-        # have to use full-on encoding for statements and parameters before
-        # passing to cursor.execute().
-        supports_unicode_statements = False
-
     supports_server_side_cursors = True
 
     default_paramstyle = "pyformat"
@@ -694,8 +667,6 @@ class PGDialect_psycopg2(PGDialect):
         PGDialect.colspecs,
         {
             sqltypes.Numeric: _PGNumeric,
-            ENUM: _PGEnum,  # needs force_unicode
-            sqltypes.Enum: _PGEnum,  # needs force_unicode
             HSTORE: _PGHStore,
             JSON: _PGJSON,
             sqltypes.JSON: _PGJSON,
@@ -718,7 +689,7 @@ class PGDialect_psycopg2(PGDialect):
     ):
         PGDialect.__init__(self, **kwargs)
         self.use_native_unicode = use_native_unicode
-        if not use_native_unicode and not util.py2k:
+        if not use_native_unicode:
             raise exc.ArgumentError(
                 "psycopg2 native_unicode mode is required under Python 3"
             )
@@ -854,7 +825,6 @@ class PGDialect_psycopg2(PGDialect):
 
     def on_connect(self):
         extras = self._psycopg2_extras
-        extensions = self._psycopg2_extensions
 
         fns = []
         if self.client_encoding is not None:
@@ -878,14 +848,6 @@ class PGDialect_psycopg2(PGDialect):
 
             fns.append(on_connect)
 
-        if util.py2k and self.dbapi and self.use_native_unicode:
-
-            def on_connect(conn):
-                extensions.register_type(extensions.UNICODE, conn)
-                extensions.register_type(extensions.UNICODEARRAY, conn)
-
-            fns.append(on_connect)
-
         if self.dbapi and self.use_native_hstore:
 
             def on_connect(conn):
@@ -893,8 +855,6 @@ class PGDialect_psycopg2(PGDialect):
                 if hstore_oids is not None:
                     oid, array_oid = hstore_oids
                     kw = {"oid": oid}
-                    if util.py2k:
-                        kw["unicode"] = True
                     kw["array_oid"] = array_oid
                     extras.register_hstore(conn, **kw)
 
index e9d5d96827ff7e88a0e69d3a40933c9081a2803e..10912e0d58e00eb4bb4e4b11e62f10b45ae4ce43 100644 (file)
@@ -454,23 +454,14 @@ class SQLiteDialect_pysqlite(SQLiteDialect):
         },
     )
 
-    if not util.py2k:
-        description_encoding = None
+    description_encoding = None
 
     driver = "pysqlite"
 
     @classmethod
     def dbapi(cls):
-        if util.py2k:
-            try:
-                from pysqlite2 import dbapi2 as sqlite
-            except ImportError:
-                try:
-                    from sqlite3 import dbapi2 as sqlite
-                except ImportError as e:
-                    raise e
-        else:
-            from sqlite3 import dbapi2 as sqlite
+        from sqlite3 import dbapi2 as sqlite
+
         return sqlite
 
     @classmethod
index 373c908042a2cd409111ce071cdbee57643bf4dd..9ec6783b02e104df7e209076b4136d8427cd45e1 100644 (file)
@@ -464,12 +464,7 @@ class DefaultDialect(interfaces.Dialect):
         return self.get_isolation_level(dbapi_conn)
 
     def _check_unicode_returns(self, connection, additional_tests=None):
-        # this now runs in py2k only and will be removed in 2.0; disabled for
-        # Python 3 in all cases under #5315
-        if util.py2k and not self.supports_unicode_statements:
-            cast_to = util.binary_type
-        else:
-            cast_to = util.text_type
+        cast_to = util.text_type
 
         if self.positional:
             parameters = self.execute_sequence_format()
@@ -523,12 +518,7 @@ class DefaultDialect(interfaces.Dialect):
             )
 
     def _check_unicode_description(self, connection):
-        # all DBAPIs on Py2K return cursor.description as encoded
-
-        if util.py2k and not self.supports_unicode_statements:
-            cast_to = util.binary_type
-        else:
-            cast_to = util.text_type
+        cast_to = util.text_type
 
         cursor = connection.connection.cursor()
         try:
@@ -722,9 +712,6 @@ class DefaultDialect(interfaces.Dialect):
     def normalize_name(self, name):
         if name is None:
             return None
-        if util.py2k:
-            if isinstance(name, str):
-                name = name.decode(self.encoding)
 
         name_lower = name.lower()
         name_upper = name.upper()
@@ -763,11 +750,6 @@ class DefaultDialect(interfaces.Dialect):
             self.identifier_preparer._requires_quotes
         )(name_lower):
             name = name_upper
-        if util.py2k:
-            if not self.supports_unicode_binds:
-                name = name.encode(self.encoding)
-            else:
-                name = unicode(name)  # noqa
         return name
 
     def get_driver_connection(self, connection):
@@ -968,12 +950,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext):
 
             self.executemany = len(parameters) > 1
 
-        # this must occur before create_cursor() since the statement
-        # has to be regexed in some cases for server side cursor
-        if util.py2k:
-            self.unicode_statement = util.text_type(compiled.string)
-        else:
-            self.unicode_statement = compiled.string
+        self.unicode_statement = compiled.string
 
         self.cursor = self.create_cursor()
 
index 21d68a1a29bb88548b00912f5733adfa12268f13..fed353e9cdea17a28327b86b529d048ac25a3e80 100644 (file)
@@ -766,12 +766,6 @@ class Inspector(object):
             # returned them
             table._validate_dialect_kwargs(tbl_opts)
 
-        if util.py2k:
-            if isinstance(schema, str):
-                schema = schema.decode(dialect.encoding)
-            if isinstance(table_name, str):
-                table_name = table_name.decode(dialect.encoding)
-
         found_table = False
         cols_by_orig_name = {}
 
index 48572c7fe07c2872333aa1e2c2216f135330f394..dcf57f6e961e1df4bdf4271a6f40b17562aeb222 100644 (file)
@@ -20,7 +20,6 @@ from ..sql.base import _generative
 from ..sql.base import HasMemoized
 from ..sql.base import InPlaceGenerative
 from ..util import collections_abc
-from ..util import py2k
 
 
 if _baserow_usecext:
@@ -658,7 +657,6 @@ class ResultInternal(InPlaceGenerative):
 
 class _WithKeys(object):
     # used mainly to share documentation on the keys method.
-    # py2k does not allow overriding the __doc__ attribute.
     def keys(self):
         """Return an iterable view which yields the string keys that would
         be represented by each :class:`.Row`.
@@ -924,11 +922,6 @@ class Result(_WithKeys, ResultInternal):
     def __next__(self):
         return self._next_impl()
 
-    if py2k:
-
-        def next(self):  # noqa
-            return self._next_impl()
-
     def partitions(self, size=None):
         """Iterate through sub-lists of rows of the size given.
 
@@ -1325,11 +1318,6 @@ class ScalarResult(FilterResult):
     def __next__(self):
         return self._next_impl()
 
-    if py2k:
-
-        def next(self):  # noqa
-            return self._next_impl()
-
     def first(self):
         """Fetch the first object or None if no object is present.
 
@@ -1468,11 +1456,6 @@ class MappingResult(_WithKeys, FilterResult):
     def __next__(self):
         return self._next_impl()
 
-    if py2k:
-
-        def next(self):  # noqa
-            return self._next_impl()
-
     def first(self):
         """Fetch the first object or None if no object is present.
 
index 488f7395270f105268b4ee447c9acfcf605a620d..be330eb6c72de03c7e4af78665a5cd356d210c18 100644 (file)
@@ -745,8 +745,6 @@ def _parse_rfc1738_args(name):
             query = {}
 
             for key, value in util.parse_qsl(components["query"]):
-                if util.py2k:
-                    key = key.encode("ascii")
                 if key in query:
                     query[key] = util.to_list(query[key])
                     query[key].append(value)
index dd5c10ac956039a98d87c338e39d3ec2864a1df5..a93f2c22908d89df6c5256779054b7ab98017428 100644 (file)
@@ -1295,30 +1295,11 @@ class _AssociationDict(_AssociationCollection):
     def keys(self):
         return self.col.keys()
 
-    if util.py2k:
+    def items(self):
+        return ((key, self._get(self.col[key])) for key in self.col)
 
-        def iteritems(self):
-            return ((key, self._get(self.col[key])) for key in self.col)
-
-        def itervalues(self):
-            return (self._get(self.col[key]) for key in self.col)
-
-        def iterkeys(self):
-            return self.col.iterkeys()
-
-        def values(self):
-            return [self._get(member) for member in self.col.values()]
-
-        def items(self):
-            return [(k, self._get(self.col[k])) for k in self]
-
-    else:
-
-        def items(self):
-            return ((key, self._get(self.col[key])) for key in self.col)
-
-        def values(self):
-            return (self._get(self.col[key]) for key in self.col)
+    def values(self):
+        return (self._get(self.col[key]) for key in self.col)
 
     def pop(self, key, default=_NotProvided):
         if default is _NotProvided:
index ec4d00cb0b3173b13771caccdd2bfc1ac46b7991..f9afd4ebfe611b544040745526ac378e167ce890 100644 (file)
@@ -1250,27 +1250,6 @@ def _list_decorators():
         _tidy(__delitem__)
         return __delitem__
 
-    if util.py2k:
-
-        def __setslice__(fn):
-            def __setslice__(self, start, end, values):
-                for value in self[start:end]:
-                    __del(self, value)
-                values = [__set(self, value) for value in values]
-                fn(self, start, end, values)
-
-            _tidy(__setslice__)
-            return __setslice__
-
-        def __delslice__(fn):
-            def __delslice__(self, start, end):
-                for value in self[start:end]:
-                    __del(self, value)
-                fn(self, start, end)
-
-            _tidy(__delslice__)
-            return __delslice__
-
     def extend(fn):
         def extend(self, iterable):
             for value in iterable:
@@ -1300,16 +1279,14 @@ def _list_decorators():
         _tidy(pop)
         return pop
 
-    if not util.py2k:
-
-        def clear(fn):
-            def clear(self, index=-1):
-                for item in self:
-                    __del(self, item)
-                fn(self)
+    def clear(fn):
+        def clear(self, index=-1):
+            for item in self:
+                __del(self, item)
+            fn(self)
 
-            _tidy(clear)
-            return clear
+        _tidy(clear)
+        return clear
 
     # __imul__ : not wrapping this.  all members of the collection are already
     # present, so no need to fire appends... wrapping it with an explicit
index 69d80dd8bdbaae82728fec838b21e49c4f5f0e18..fcc7368c41dcd205fb1b219d498c33613211f1da 100644 (file)
@@ -33,7 +33,6 @@ _straight_ops = set(
         "add",
         "mul",
         "sub",
-        "div",
         "mod",
         "truediv",
         "lt",
index 6aea0d18547c9fd3d00577eef49234033a575386..10d924b4850fa65a74d8491d2723f9d12f599c62 100644 (file)
@@ -9,7 +9,6 @@ import weakref
 
 from . import util as orm_util
 from .. import exc as sa_exc
-from .. import util
 
 
 class IdentityMap(object):
@@ -201,19 +200,8 @@ class WeakInstanceDict(IdentityMap):
     def __iter__(self):
         return iter(self.keys())
 
-    if util.py2k:
-
-        def iteritems(self):
-            return iter(self.items())
-
-        def itervalues(self):
-            return iter(self.values())
-
     def all_states(self):
-        if util.py2k:
-            return self._dict.values()
-        else:
-            return list(self._dict.values())
+        return list(self._dict.values())
 
     def _fast_discard(self, state):
         # used by InstanceState for state being
index 02fc7379322e67701df87f570406ef319dfb28d8..626643ce13a2c71a2fa17fdefb7ea6345692a0e8 100644 (file)
@@ -628,12 +628,8 @@ def __init__(%(apply_pos)s):
     func_vars = util.format_argspec_init(original_init, grouped=False)
     func_text = func_body % func_vars
 
-    if util.py2k:
-        func = getattr(original_init, "im_func", original_init)
-        func_defaults = getattr(func, "func_defaults", None)
-    else:
-        func_defaults = getattr(original_init, "__defaults__", None)
-        func_kw_defaults = getattr(original_init, "__kwdefaults__", None)
+    func_defaults = getattr(original_init, "__defaults__", None)
+    func_kw_defaults = getattr(original_init, "__kwdefaults__", None)
 
     env = locals().copy()
     env["__name__"] = __name__
@@ -644,7 +640,7 @@ def __init__(%(apply_pos)s):
 
     if func_defaults:
         __init__.__defaults__ = func_defaults
-    if not util.py2k and func_kw_defaults:
+    if func_kw_defaults:
         __init__.__kwdefaults__ = func_kw_defaults
 
     return __init__
index 7a2333d91db8c2260571e8db2d4cbd5b7a770d2d..bcede5d7676295af560420c84ec7fb664214d62b 100644 (file)
@@ -175,7 +175,6 @@ OPERATORS = {
     operators.add: " + ",
     operators.mul: " * ",
     operators.sub: " - ",
-    operators.div: " / ",
     operators.mod: " % ",
     operators.truediv: " / ",
     operators.neg: "-",
index e883454de65f60fa8048a73cb2983641e197f69e..f1fe46fd2346a518cfa1bb8d007ca1e9d519e398 100644 (file)
@@ -5158,15 +5158,6 @@ class quoted_name(util.MemoizedSlots, util.text_type):
         else:
             return util.text_type(self).upper()
 
-    def __repr__(self):
-        if util.py2k:
-            backslashed = self.encode("ascii", "backslashreplace")
-            if not util.py2k:
-                backslashed = backslashed.decode("ascii")
-            return "'%s'" % backslashed
-        else:
-            return str.__repr__(self)
-
 
 def _find_columns(clause):
     """locate Column objects within the given expression."""
index 695e086b88fd8bf8373e0b16d90d1504da29551a..b64bea07a06fbbc0ac3fa61891fdb3476e5bcf6d 100644 (file)
@@ -33,12 +33,6 @@ from operator import truediv
 from .. import util
 
 
-if util.py2k:
-    from operator import div
-else:
-    div = truediv
-
-
 class Operators(object):
     """Base of comparison and logical operators.
 
@@ -1130,14 +1124,6 @@ class ColumnOperators(Operators):
         """
         return self.reverse_operate(mul, other)
 
-    def __rdiv__(self, other):
-        """Implement the ``/`` operator in reverse.
-
-        See :meth:`.ColumnOperators.__div__`.
-
-        """
-        return self.reverse_operate(div, other)
-
     def __rmod__(self, other):
         """Implement the ``%`` operator in reverse.
 
@@ -1223,14 +1209,6 @@ class ColumnOperators(Operators):
         """
         return self.operate(mul, other)
 
-    def __div__(self, other):
-        """Implement the ``/`` operator.
-
-        In a column context, produces the clause ``a / b``.
-
-        """
-        return self.operate(div, other)
-
     def __mod__(self, other):
         """Implement the ``%`` operator.
 
@@ -1240,7 +1218,7 @@ class ColumnOperators(Operators):
         return self.operate(mod, other)
 
     def __truediv__(self, other):
-        """Implement the ``//`` operator.
+        """Implement the ``/`` operator.
 
         In a column context, produces the clause ``a / b``.
 
@@ -1248,7 +1226,7 @@ class ColumnOperators(Operators):
         return self.operate(truediv, other)
 
     def __rtruediv__(self, other):
-        """Implement the ``//`` operator in reverse.
+        """Implement the ``/`` operator in reverse.
 
         See :meth:`.ColumnOperators.__truediv__`.
 
@@ -1610,7 +1588,6 @@ _PRECEDENCE = {
     json_path_getitem_op: 15,
     mul: 8,
     truediv: 8,
-    div: 8,
     mod: 8,
     neg: 8,
     add: 7,
index ae589d648a8a8b7c742206284069da590266682f..77af76d0b8d5242dafd0d070d863a9e3882fd51d 100644 (file)
@@ -555,7 +555,6 @@ class Integer(_LookupExpressionAdapter, TypeEngine):
                 Integer: self.__class__,
                 Numeric: Numeric,
             },
-            operators.div: {Integer: self.__class__, Numeric: Numeric},
             operators.truediv: {Integer: self.__class__, Numeric: Numeric},
             operators.sub: {Integer: self.__class__, Numeric: Numeric},
         }
@@ -753,7 +752,6 @@ class Numeric(_LookupExpressionAdapter, TypeEngine):
                 Numeric: self.__class__,
                 Integer: self.__class__,
             },
-            operators.div: {Numeric: self.__class__, Integer: self.__class__},
             operators.truediv: {
                 Numeric: self.__class__,
                 Integer: self.__class__,
@@ -985,20 +983,13 @@ class _Binary(TypeEngine):
     # Python 3 has native bytes() type
     # both sqlite3 and pg8000 seem to return it,
     # psycopg2 as of 2.5 returns 'memoryview'
-    if util.py2k:
-
-        def result_processor(self, dialect, coltype):
-            return processors.to_str
-
-    else:
-
-        def result_processor(self, dialect, coltype):
-            def process(value):
-                if value is not None:
-                    value = bytes(value)
-                return value
+    def result_processor(self, dialect, coltype):
+        def process(value):
+            if value is not None:
+                value = bytes(value)
+            return value
 
-            return process
+        return process
 
     def coerce_compared_value(self, op, value):
         """See :meth:`.TypeEngine.coerce_compared_value` for a description."""
@@ -1494,14 +1485,7 @@ class Enum(Emulated, String, SchemaType):
         self.validate_strings = kw.pop("validate_strings", False)
 
         if convert_unicode is None:
-            for e in self.enums:
-                # this is all py2k logic that can go away for py3k only,
-                # "expect unicode" will always be implicitly true
-                if isinstance(e, util.text_type):
-                    _expect_unicode = True
-                    break
-            else:
-                _expect_unicode = False
+            _expect_unicode = True
         else:
             _expect_unicode = convert_unicode
 
@@ -2011,7 +1995,6 @@ class _AbstractInterval(_LookupExpressionAdapter, TypeEngine):
             operators.sub: {Interval: self.__class__},
             operators.mul: {Numeric: self.__class__},
             operators.truediv: {Numeric: self.__class__},
-            operators.div: {Numeric: self.__class__},
         }
 
     @property
index 2a4688bcceb3c9e75c30966a12176e877cc39fcf..f588512687cbeb7b404956f96c82215d5471a297 100644 (file)
@@ -800,12 +800,7 @@ class TypeEngine(Traversible):
         return default.StrCompileDialect()
 
     def __str__(self):
-        if util.py2k:
-            return unicode(self.compile()).encode(  # noqa
-                "ascii", "backslashreplace"
-            )  # noqa
-        else:
-            return str(self.compile())
+        return str(self.compile())
 
     def __repr__(self):
         return util.generic_repr(self)
index d5522289b4fe314a22119bc8ae8c281ce0917359..e8fce5a4c876e7efc063c8c506c46efec32a7b52 100644 (file)
@@ -139,16 +139,10 @@ class compound(object):
     def _expect_failure(self, config, ex, name="block"):
         for fail in self.fails:
             if fail(config):
-                if util.py2k:
-                    str_ex = unicode(ex).encode(  # noqa: F821
-                        "utf-8", errors="ignore"
-                    )
-                else:
-                    str_ex = str(ex)
                 print(
                     (
                         "%s failed as expected (%s): %s "
-                        % (name, fail._as_string(config), str_ex)
+                        % (name, fail._as_string(config), ex)
                     )
                 )
                 break
index b4691c57d421a7960e490e171cebea09d1233ddf..1220561e868530c14d5c13eb33b777d32f1a5897 100644 (file)
@@ -41,10 +41,6 @@ def load_file_as_module(name):
 if to_bootstrap == "pytest":
     sys.modules["sqla_plugin_base"] = load_file_as_module("plugin_base")
     sys.modules["sqla_plugin_base"].bootstrapped_as_sqlalchemy = True
-    if sys.version_info < (3, 0):
-        sys.modules["sqla_reinvent_fixtures"] = load_file_as_module(
-            "reinvent_fixtures_py2k"
-        )
     sys.modules["sqla_pytestplugin"] = load_file_as_module("pytestplugin")
 else:
     raise Exception("unknown bootstrap: %s" % to_bootstrap)  # noqa
index 6c6287060b700a93892c0c0316647501aee5e5f6..36aaa5d2a4464767a71a4ad143fef103a49cd8d3 100644 (file)
@@ -25,14 +25,6 @@ except ImportError:
     has_xdist = False
 
 
-py2k = sys.version_info < (3, 0)
-if py2k:
-    try:
-        import sqla_reinvent_fixtures as reinvent_fixtures_py2k
-    except ImportError:
-        from . import reinvent_fixtures_py2k
-
-
 def pytest_addoption(parser):
     group = parser.getgroup("sqlalchemy")
 
@@ -238,10 +230,6 @@ def pytest_collection_modifyitems(session, config, items):
         else:
             newitems.append(item)
 
-    if py2k:
-        for item in newitems:
-            reinvent_fixtures_py2k.scan_for_fixtures_to_use_for_class(item)
-
     # seems like the functions attached to a test class aren't sorted already?
     # is that true and why's that? (when using unittest, they're sorted)
     items[:] = sorted(
@@ -340,9 +328,7 @@ def _parametrize_cls(module, cls):
             for arg, val in zip(argname_split, param.values):
                 cls_variables[arg] = val
         parametrized_name = "_".join(
-            # token is a string, but in py2k pytest is giving us a unicode,
-            # so call str() on it.
-            str(re.sub(r"\W", "", token))
+            re.sub(r"\W", "", token)
             for param in full_param_set
             for token in param.id.split("-")
         )
@@ -457,14 +443,8 @@ def setup_class_methods(request):
     if hasattr(cls, "setup_test_class"):
         asyncio._maybe_async(cls.setup_test_class)
 
-    if py2k:
-        reinvent_fixtures_py2k.run_class_fixture_setup(request)
-
     yield
 
-    if py2k:
-        reinvent_fixtures_py2k.run_class_fixture_teardown(request)
-
     if hasattr(cls, "teardown_test_class"):
         asyncio._maybe_async(cls.teardown_test_class)
 
@@ -484,9 +464,7 @@ def setup_test_methods(request):
     # 1. function level "autouse" fixtures under py3k (examples: TablesTest
     #    define tables / data, MappedTest define tables / mappers / data)
 
-    # 2. run homegrown function level "autouse" fixtures under py2k
-    if py2k:
-        reinvent_fixtures_py2k.run_fn_fixture_setup(request)
+    # 2. was for p2k. no longer applies
 
     # 3. run outer xdist-style setup
     if hasattr(self, "setup_test"):
@@ -529,9 +507,7 @@ def setup_test_methods(request):
     if hasattr(self, "teardown_test"):
         asyncio._maybe_async(self.teardown_test)
 
-    # 11. run homegrown function-level "autouse" fixtures under py2k
-    if py2k:
-        reinvent_fixtures_py2k.run_fn_fixture_teardown(request)
+    # 11. was for p2k. no longer applies
 
     # 12. function level "autouse" fixtures under py3k (examples: TablesTest /
     #    MappedTest delete table data, possibly drop tables and clear mappers
@@ -778,17 +754,8 @@ class PytestFixtureFunctions(plugin_base.FixtureFunctions):
                 fn = asyncio._maybe_async_wrapper(fn)
             # other wrappers may be added here
 
-            if py2k and "autouse" in kw:
-                # py2k workaround for too-slow collection of autouse fixtures
-                # in pytest 4.6.11.  See notes in reinvent_fixtures_py2k for
-                # rationale.
-
-                # comment this condition out in order to disable the
-                # py2k workaround entirely.
-                reinvent_fixtures_py2k.add_fixture(fn, fixture)
-            else:
-                # now apply FixtureFunctionMarker
-                fn = fixture(fn)
+            # now apply FixtureFunctionMarker
+            fn = fixture(fn)
 
             return fn
 
diff --git a/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py b/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py
deleted file mode 100644 (file)
index 36b6841..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-"""
-invent a quick version of pytest autouse fixtures as pytest's unacceptably slow
-collection/high memory use in pytest 4.6.11, which is the highest version that
-works in py2k.
-
-by "too-slow" we mean the test suite can't even manage to be collected for a
-single process in less than 70 seconds or so and memory use seems to be very
-high as well.   for two or four workers the job just times out after ten
-minutes.
-
-so instead we have invented a very limited form of these fixtures, as our
-current use of "autouse" fixtures are limited to those in fixtures.py.
-
-assumptions for these fixtures:
-
-1. we are only using "function" or "class" scope
-
-2. the functions must be associated with a test class
-
-3. the fixture functions cannot themselves use pytest fixtures
-
-4. the fixture functions must use yield, not return
-
-When py2k support is removed and we can stay on a modern pytest version, this
-can all be removed.
-
-
-"""
-import collections
-
-
-_py2k_fixture_fn_names = collections.defaultdict(set)
-_py2k_class_fixtures = collections.defaultdict(
-    lambda: collections.defaultdict(set)
-)
-_py2k_function_fixtures = collections.defaultdict(
-    lambda: collections.defaultdict(set)
-)
-
-_py2k_cls_fixture_stack = []
-_py2k_fn_fixture_stack = []
-
-
-def add_fixture(fn, fixture):
-    assert fixture.scope in ("class", "function")
-    _py2k_fixture_fn_names[fn.__name__].add((fn, fixture.scope))
-
-
-def scan_for_fixtures_to_use_for_class(item):
-    test_class = item.parent.parent.obj
-
-    for name in _py2k_fixture_fn_names:
-        for fixture_fn, scope in _py2k_fixture_fn_names[name]:
-            meth = getattr(test_class, name, None)
-            if meth and meth.im_func is fixture_fn:
-                for sup in test_class.__mro__:
-                    if name in sup.__dict__:
-                        if scope == "class":
-                            _py2k_class_fixtures[test_class][sup].add(meth)
-                        elif scope == "function":
-                            _py2k_function_fixtures[test_class][sup].add(meth)
-                        break
-                break
-
-
-def run_class_fixture_setup(request):
-
-    cls = request.cls
-    self = cls.__new__(cls)
-
-    fixtures_for_this_class = _py2k_class_fixtures.get(cls)
-
-    if fixtures_for_this_class:
-        for sup_ in cls.__mro__:
-            for fn in fixtures_for_this_class.get(sup_, ()):
-                iter_ = fn(self)
-                next(iter_)
-
-                _py2k_cls_fixture_stack.append(iter_)
-
-
-def run_class_fixture_teardown(request):
-    while _py2k_cls_fixture_stack:
-        iter_ = _py2k_cls_fixture_stack.pop(-1)
-        try:
-            next(iter_)
-        except StopIteration:
-            pass
-
-
-def run_fn_fixture_setup(request):
-    cls = request.cls
-    self = request.instance
-
-    fixtures_for_this_class = _py2k_function_fixtures.get(cls)
-
-    if fixtures_for_this_class:
-        for sup_ in reversed(cls.__mro__):
-            for fn in fixtures_for_this_class.get(sup_, ()):
-                iter_ = fn(self)
-                next(iter_)
-
-                _py2k_fn_fixture_stack.append(iter_)
-
-
-def run_fn_fixture_teardown(request):
-    while _py2k_fn_fixture_stack:
-        iter_ = _py2k_fn_fixture_stack.pop(-1)
-        try:
-            next(iter_)
-        except StopIteration:
-            pass
index 3cf5c853e34e50ea7903036610957683360ae7ef..8b385b5d2dfc1db67502266f06cd16da472a0eb6 100644 (file)
@@ -1217,45 +1217,6 @@ class SuiteRequirements(Requirements):
 
         return exclusions.only_if(check)
 
-    @property
-    def python2(self):
-        return exclusions.skip_if(
-            lambda: sys.version_info >= (3,),
-            "Python version 2.xx is required.",
-        )
-
-    @property
-    def python3(self):
-        return exclusions.skip_if(
-            lambda: sys.version_info < (3,), "Python version 3.xx is required."
-        )
-
-    @property
-    def pep520(self):
-        return self.python36
-
-    @property
-    def insert_order_dicts(self):
-        return self.python37
-
-    @property
-    def python36(self):
-        return exclusions.skip_if(
-            lambda: sys.version_info < (3, 6),
-            "Python version 3.6 or greater is required.",
-        )
-
-    @property
-    def python37(self):
-        return exclusions.skip_if(
-            lambda: sys.version_info < (3, 7),
-            "Python version 3.7 or greater is required.",
-        )
-
-    @property
-    def dataclasses(self):
-        return self.python37
-
     @property
     def cpython(self):
         return exclusions.only_if(
index c2c17d0ddd1cfd43fa64f2063e6a2d19e416abcd..32dfdedadcce036ce961fad4967dea7fc58483ca 100644 (file)
@@ -19,7 +19,6 @@ from ... import Integer
 from ... import literal_column
 from ... import select
 from ... import String
-from ...util import compat
 
 
 class ExceptionTest(fixtures.TablesTest):
@@ -77,12 +76,7 @@ class ExceptionTest(fixtures.TablesTest):
 
                 assert str(err.orig) in str(err)
 
-            # test that we are actually getting string on Py2k, unicode
-            # on Py3k.
-            if compat.py2k:
-                assert isinstance(err_str, str)
-            else:
-                assert isinstance(err_str, str)
+            assert isinstance(err_str, str)
 
 
 class IsolationLevelTest(fixtures.TestBase):
index 22b85f398d92657df546a546fe84f5f6e93b90a6..93d37d4d50be143e8ee0292144f76abe9566f284 100644 (file)
@@ -873,8 +873,11 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
             ("numeric", 1234567.89),
             # this one "works" because the float value you see here is
             # lost immediately to floating point stuff
-            ("numeric", 99998969694839.983485848, requirements.python3),
-            ("numeric", 99939.983485848, requirements.python3),
+            (
+                "numeric",
+                99998969694839.983485848,
+            ),
+            ("numeric", 99939.983485848),
             ("_decimal", decimal.Decimal("1234567.89")),
             (
                 "_decimal",
@@ -991,8 +994,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
 
             roundtrip = conn.scalar(select(expr))
             eq_(roundtrip, compare_value)
-            if util.py3k:  # skip py2k to avoid comparing unicode to str etc.
-                is_(type(roundtrip), type(compare_value))
+            is_(type(roundtrip), type(compare_value))
 
     @_index_fixtures(True)
     @testing.emits_warning(r".*does \*not\* support Decimal objects natively")
index a4ae3348ed6005e82bce4f7bb7ce46efb063e9c0..1334eb8dbf32b0c0b4eafe3f1f2aff0e1e855b0e 100644 (file)
@@ -6,7 +6,6 @@ from sqlalchemy import ForeignKey
 from sqlalchemy import Integer
 from sqlalchemy import MetaData
 from sqlalchemy import testing
-from sqlalchemy import util
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing.schema import Column
@@ -183,24 +182,12 @@ class UnicodeSchemaTest(fixtures.TablesTest):
         t = Table(
             ue("\u6e2c\u8a66"), meta, Column(ue("\u6e2c\u8a66_id"), Integer)
         )
-
-        if util.py2k:
-            eq_(
-                repr(t),
-                (
-                    "Table('\\u6e2c\\u8a66', MetaData(), "
-                    "Column('\\u6e2c\\u8a66_id', Integer(), "
-                    "table=<\u6e2c\u8a66>), "
-                    "schema=None)"
-                ),
-            )
-        else:
-            eq_(
-                repr(t),
-                (
-                    "Table('測試', MetaData(), "
-                    "Column('測試_id', Integer(), "
-                    "table=<測試>), "
-                    "schema=None)"
-                ),
-            )
+        eq_(
+            repr(t),
+            (
+                "Table('測試', MetaData(), "
+                "Column('測試_id', Integer(), "
+                "table=<測試>), "
+                "schema=None)"
+            ),
+        )
index a4d55a8f2cbadaf3d005f895bb0a06d82a333222..982e5751777d69ea0e6401b67e1871fb0ff560ae 100644 (file)
@@ -27,7 +27,6 @@ from ..util import decorator
 from ..util import defaultdict
 from ..util import has_refcount_gc
 from ..util import inspect_getfullargspec
-from ..util import py2k
 
 
 if not has_refcount_gc:
@@ -47,14 +46,6 @@ else:
 
 def picklers():
     picklers = set()
-    if py2k:
-        try:
-            import cPickle
-
-            picklers.add(cPickle)
-        except ImportError:
-            pass
-
     import pickle
 
     picklers.add(pickle)
@@ -65,19 +56,8 @@ def picklers():
             yield pickle_.loads, lambda d: pickle_.dumps(d, protocol)
 
 
-if py2k:
-
-    def random_choices(population, k=1):
-        pop = list(population)
-        # lame but works :)
-        random.shuffle(pop)
-        return pop[0:k]
-
-
-else:
-
-    def random_choices(population, k=1):
-        return random.choices(population, k=k)
+def random_choices(population, k=1):
+    return random.choices(population, k=k)
 
 
 def round_decimal(value, prec):
index bdd69431e0f81c3f731b416266139a51a481fc9d..327f767159eafd658895fdc1df74d440699cb737 100644 (file)
@@ -75,7 +75,6 @@ from .compat import parse_qsl
 from .compat import perf_counter
 from .compat import pickle
 from .compat import print_
-from .compat import py2k
 from .compat import py37
 from .compat import py38
 from .compat import py39
index 535ae47802f1b4125b1f730a1fcd3739af2045cd..54ed522d470f9858c447f60be754758d25d38d49 100644 (file)
@@ -16,7 +16,6 @@ import weakref
 from .compat import binary_types
 from .compat import collections_abc
 from .compat import itertools_filterfalse
-from .compat import py2k
 from .compat import py37
 from .compat import string_types
 from .compat import threading
@@ -322,17 +321,6 @@ else:
         def items(self):
             return [(key, self[key]) for key in self._list]
 
-        if py2k:
-
-            def itervalues(self):
-                return iter(self.values())
-
-            def iterkeys(self):
-                return iter(self)
-
-            def iteritems(self):
-                return iter(self.items())
-
         def __setitem__(self, key, obj):
             if key not in self:
                 try:
index 5914e8681aad2e5e7e741e95f5b20aecfb24c1af..5749b33375b5e1669ac346657e1e561f16d5ca40 100644 (file)
@@ -18,7 +18,6 @@ py39 = sys.version_info >= (3, 9)
 py38 = sys.version_info >= (3, 8)
 py37 = sys.version_info >= (3, 7)
 py3k = sys.version_info >= (3, 0)
-py2k = sys.version_info < (3, 0)
 pypy = platform.python_implementation() == "PyPy"
 
 
index 89ca4c1ebf6dffa043b2f9de47a20818a886a914..84c5fddec98883a15c83cfe26272336475fa0f08 100644 (file)
@@ -304,7 +304,7 @@ def %(name)s(%(args)s):
             % (decorated.__module__,)
         )
 
-    if compat.py2k or hasattr(fn, "__func__"):
+    if hasattr(fn, "__func__"):
         fn.__func__.__doc__ = doc
         if not hasattr(fn.__func__, "_linked_to"):
             fn.__func__._linked_to = (decorated, location)
@@ -888,24 +888,12 @@ def class_hierarchy(cls):
     will not be descended.
 
     """
-    if compat.py2k:
-        if isinstance(cls, types.ClassType):
-            return list()
 
     hier = {cls}
     process = list(cls.__mro__)
     while process:
         c = process.pop()
-        if compat.py2k:
-            if isinstance(c, types.ClassType):
-                continue
-            bases = (
-                _
-                for _ in c.__bases__
-                if _ not in hier and not isinstance(_, types.ClassType)
-            )
-        else:
-            bases = (_ for _ in c.__bases__ if _ not in hier)
+        bases = (_ for _ in c.__bases__ if _ not in hier)
 
         for b in bases:
             process.append(b)
index ba3283f55637eba7e20496bf5e3a91a1777ba72a..3d6700542e3e238dac2a39f8d9e10e74aa85c192 100644 (file)
@@ -50,8 +50,7 @@ class EnumTest(fixtures.TestBase):
 
 
 class CacheKeyTest(fixtures.TestBase):
-    # python3 is just to have less variability in test counts
-    __requires__ = ("cpython", "python_profiling_backend", "python3")
+    __requires__ = ("cpython", "python_profiling_backend")
 
     @testing.fixture(scope="class")
     def mapping_fixture(self):
index 0b648aa30bdd8ba741351db57ba9f92a1fead99e..3c89108ee3893571fe3cc7bd598a08b2b1f026df 100644 (file)
@@ -1,7 +1,6 @@
 import threading
 
 from sqlalchemy import exc
-from sqlalchemy import testing
 from sqlalchemy.testing import async_test
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import expect_raises
@@ -141,7 +140,6 @@ class TestAsyncioCompat(fixtures.TestBase):
         await to_await
 
     @async_test
-    @testing.requires.python37
     async def test_contextvars(self):
         import asyncio
         import contextvars
@@ -186,9 +184,7 @@ class TestAsyncioCompat(fixtures.TestBase):
 
 
 class TestAsyncAdaptedQueue(fixtures.TestBase):
-    # uses asyncio.run() in alternate threads which is not available
-    # in Python 3.6
-    __requires__ = ("python37", "greenlet")
+    __requires__ = ("greenlet",)
 
     def test_lazy_init(self):
         run = [False]
index 68db5207ca0aad17eb218d74a3d6356c78634d16..d38f61c1ea9d1947edd1a60b567e5ca3f1871122 100644 (file)
@@ -268,7 +268,6 @@ class EventsTest(TearDownLocalEventsFixture, fixtures.TestBase):
 
 
 class SlotsEventsTest(fixtures.TestBase):
-    @testing.requires.python3
     def test_no_slots_dispatch(self):
         class Target(object):
             __slots__ = ()
index f2b577216bc933d2ea8eba4f0e74fc04f349f01b..2393a7f913487fe000f1008f31954792a323bd40 100644 (file)
@@ -11,8 +11,6 @@ from sqlalchemy.testing import fixtures
 
 
 class DocTest(fixtures.TestBase):
-    __requires__ = ("python3",)
-
     def _setup_logger(self):
         rootlogger = logging.getLogger("sqlalchemy.engine.Engine")
 
index 849c193eac3f8f7699a86ac587c0d2303bd184b2..81e402d93dbc255dfdae0ed1801ec720351e0feb 100644 (file)
@@ -14,7 +14,6 @@ from sqlalchemy.sql.base import DedupeColumnCollection
 from sqlalchemy.testing import assert_raises
 from sqlalchemy.testing import assert_raises_message
 from sqlalchemy.testing import eq_
-from sqlalchemy.testing import expect_warnings
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing import in_
 from sqlalchemy.testing import is_
@@ -133,12 +132,8 @@ class OrderedDictTest(fixtures.TestBase):
 
     def test_no_sort_legacy_dictionary(self):
         d1 = {"c": 1, "b": 2, "a": 3}
-
-        if testing.requires.python37.enabled:
-            util.sort_dictionary(d1)
-            eq_(list(d1), ["a", "b", "c"])
-        else:
-            assert_raises(AttributeError, util.sort_dictionary, d1)
+        util.sort_dictionary(d1)
+        eq_(list(d1), ["a", "b", "c"])
 
     def test_sort_dictionary(self):
         o = util.OrderedDict()
@@ -1882,26 +1877,9 @@ class DictlikeIteritemsTest(fixtures.TestBase):
         d = subdict(a=1, b=2, c=3)
         self._ok(d)
 
-    if util.py2k:
-
-        def test_UserDict(self):
-            import UserDict
-
-            d = UserDict.UserDict(a=1, b=2, c=3)
-            self._ok(d)
-
     def test_object(self):
         self._notok(object())
 
-    if util.py2k:
-
-        def test_duck_1(self):
-            class duck1(object):
-                def iteritems(duck):
-                    return iter(self.baseline)
-
-            self._ok(duck1())
-
     def test_duck_2(self):
         class duck2(object):
             def items(duck):
@@ -1909,18 +1887,6 @@ class DictlikeIteritemsTest(fixtures.TestBase):
 
         self._ok(duck2())
 
-    if util.py2k:
-
-        def test_duck_3(self):
-            class duck3(object):
-                def iterkeys(duck):
-                    return iter(["a", "b", "c"])
-
-                def __getitem__(duck, key):
-                    return dict(a=1, b=2, c=3).get(key)
-
-            self._ok(duck3())
-
     def test_duck_4(self):
         class duck4(object):
             def iterkeys(duck):
@@ -2570,7 +2536,6 @@ class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
                 "apply_kw_proxied": "a, b=b, c=c",
             },
             False,
-            testing.requires.python3,
         ),
         (
             py3k_fixtures._kw_plus_posn_fixture,
@@ -2583,7 +2548,6 @@ class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
                 "apply_kw_proxied": "a, b=b, c=c, *args",
             },
             False,
-            testing.requires.python3,
         ),
         (
             py3k_fixtures._kw_opt_fixture,
@@ -2596,7 +2560,6 @@ class TestFormatArgspec(_Py3KFixtures, fixtures.TestBase):
                 "apply_kw_proxied": "a, b=b, c=c",
             },
             False,
-            testing.requires.python3,
         ),
         argnames="fn,wanted,grouped",
     )
@@ -2983,25 +2946,8 @@ class TestClassHierarchy(fixtures.TestBase):
         eq_(set(util.class_hierarchy(A)), set((A, B, C, object)))
         eq_(set(util.class_hierarchy(B)), set((A, B, C, object)))
 
-    if util.py2k:
-
-        def test_oldstyle_mixin(self):
-            class A(object):
-                pass
-
-            class Mixin:
-                pass
-
-            class B(A, Mixin):
-                pass
-
-            eq_(set(util.class_hierarchy(B)), set((A, B, object)))
-            eq_(set(util.class_hierarchy(Mixin)), set())
-            eq_(set(util.class_hierarchy(A)), set((A, B, object)))
-
 
 class ReraiseTest(fixtures.TestBase):
-    @testing.requires.python3
     def test_raise_from_cause_same_cause(self):
         class MyException(Exception):
             pass
@@ -3037,8 +2983,7 @@ class ReraiseTest(fixtures.TestBase):
             go()
             assert False
         except MyOtherException as moe:
-            if testing.requires.python3.enabled:
-                is_(moe.__cause__, me)
+            is_(moe.__cause__, me)
 
     def test_raise_from(self):
         class MyException(Exception):
@@ -3059,40 +3004,7 @@ class ReraiseTest(fixtures.TestBase):
             go()
             assert False
         except MyOtherException as moe:
-            if testing.requires.python3.enabled:
-                is_(moe.__cause__, me)
-
-    @testing.requires.python2
-    def test_safe_reraise_py2k_warning(self):
-        class MyException(Exception):
-            pass
-
-        class MyOtherException(Exception):
-            pass
-
-        m1 = MyException("exc one")
-        m2 = MyOtherException("exc two")
-
-        def go2():
-            raise m2
-
-        def go():
-            try:
-                raise m1
-            except Exception:
-                with util.safe_reraise():
-                    go2()
-
-        with expect_warnings(
-            "An exception has occurred during handling of a previous "
-            "exception.  The previous exception "
-            "is:.*MyException.*exc one"
-        ):
-            try:
-                go()
-                assert False
-            except MyOtherException:
-                pass
+            is_(moe.__cause__, me)
 
 
 class TestClassProperty(fixtures.TestBase):
@@ -3316,20 +3228,12 @@ class TimezoneTest(fixtures.TestBase):
             datetime.datetime(2017, 10, 5, 4, 55, 38, tzinfo=timezone(del_)),
         )
 
-    @testing.requires.python3
-    def test_repr_py3k(self):
+    def test_repr(self):
         eq_(
             repr(timezone(datetime.timedelta(hours=5))),
             "datetime.timezone(%r)" % (datetime.timedelta(hours=5)),
         )
 
-    @testing.requires.python2
-    def test_repr_py2k(self):
-        eq_(
-            repr(timezone(datetime.timedelta(hours=5))),
-            "sqlalchemy.util.timezone(%r)" % (datetime.timedelta(hours=5)),
-        )
-
 
 class TestModuleRegistry(fixtures.TestBase):
     def test_modules_are_loaded(self):
index e5e3cd3ad292ed66915d9536d4fa67fbd3426207..2498de92a95921fe5a851dd047bdcff213c6e403 100644 (file)
@@ -15,7 +15,6 @@ from sqlalchemy import select
 from sqlalchemy import String
 from sqlalchemy import Table
 from sqlalchemy import testing
-from sqlalchemy import util
 from sqlalchemy.dialects.mssql import base as mssql
 from sqlalchemy.testing import AssertsCompiledSQL
 from sqlalchemy.testing import config
@@ -24,7 +23,6 @@ from sqlalchemy.testing import eq_
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing.assertsql import CursorSQL
 from sqlalchemy.testing.assertsql import DialectSQL
-from sqlalchemy.util import ue
 
 
 class IdentityInsertTest(fixtures.TablesTest, AssertsCompiledSQL):
@@ -140,39 +138,6 @@ class IdentityInsertTest(fixtures.TablesTest, AssertsCompiledSQL):
         eq_(conn.execute(select(t)).first(), (1, "descrip"))
 
 
-class QueryUnicodeTest(fixtures.TestBase):
-
-    __only_on__ = "mssql"
-    __backend__ = True
-
-    @testing.requires.mssql_freetds
-    @testing.requires.python2
-    @testing.provide_metadata
-    def test_convert_unicode(self, connection):
-        meta = self.metadata
-        t1 = Table(
-            "unitest_table",
-            meta,
-            Column("id", Integer, primary_key=True),
-            Column("descr", mssql.MSText()),
-        )
-        meta.create_all(connection)
-        connection.execute(
-            ue("insert into unitest_table values ('abc \xc3\xa9 def')").encode(
-                "UTF-8"
-            )
-        )
-        r = connection.execute(t1.select()).first()
-        assert isinstance(
-            r[1], util.text_type
-        ), "%s is %s instead of unicode, working on %s" % (
-            r[1],
-            type(r[1]),
-            meta.bind,
-        )
-        eq_(r[1], util.ue("abc \xc3\xa9 def"))
-
-
 class QueryTest(testing.AssertsExecutionResults, fixtures.TestBase):
     __only_on__ = "mssql"
     __backend__ = True
index 8e5e3f9c6924cf3faaee629fc08fa8223d1b9538..a96b74c0a8c5735d11e631431fa31e17db393b8c 100644 (file)
@@ -909,7 +909,6 @@ class TypeRoundTripTest(
             ),
             None,
             True,
-            testing.requires.python37,
         ),
         (
             "dto_param_datetime_naive",
index 554e5f18b4be58195c8841f2d5af24be63ec393a..f287a9a0b872feba86ee589f6c9920ccd2be81f3 100644 (file)
@@ -256,7 +256,6 @@ class EncodingErrorsTest(fixtures.TestBase):
             assert_raises(UnicodeDecodeError, outconverter, utf8_w_errors)
 
     @_oracle_char_combinations
-    @testing.requires.python3
     def test_older_cx_oracle_warning(self, cx_Oracle, cx_oracle_type):
         cx_Oracle.version = "6.3"
 
@@ -277,46 +276,7 @@ class EncodingErrorsTest(fixtures.TestBase):
             )
 
     @_oracle_char_combinations
-    @testing.requires.python2
-    def test_encoding_errors_sqla_py2k(
-        self,
-        cx_Oracle,
-        cx_oracle_type,
-    ):
-        ignore_dialect = cx_oracle.dialect(
-            dbapi=cx_Oracle, encoding_errors="ignore"
-        )
-
-        ignore_outputhandler = (
-            ignore_dialect._generate_connection_outputtype_handler()
-        )
-
-        cursor = mock.Mock()
-        ignore_outputhandler(cursor, "foo", cx_oracle_type, None, None, None)
-        outconverter = cursor.mock_calls[0][2]["outconverter"]
-        self._assert_errorhandler(outconverter, True)
-
-    @_oracle_char_combinations
-    @testing.requires.python2
-    def test_no_encoding_errors_sqla_py2k(
-        self,
-        cx_Oracle,
-        cx_oracle_type,
-    ):
-        plain_dialect = cx_oracle.dialect(dbapi=cx_Oracle)
-
-        plain_outputhandler = (
-            plain_dialect._generate_connection_outputtype_handler()
-        )
-
-        cursor = mock.Mock()
-        plain_outputhandler(cursor, "foo", cx_oracle_type, None, None, None)
-        outconverter = cursor.mock_calls[0][2]["outconverter"]
-        self._assert_errorhandler(outconverter, False)
-
-    @_oracle_char_combinations
-    @testing.requires.python3
-    def test_encoding_errors_cx_oracle_py3k(
+    def test_encoding_errors_cx_oracle(
         self,
         cx_Oracle,
         cx_oracle_type,
@@ -345,8 +305,7 @@ class EncodingErrorsTest(fixtures.TestBase):
         )
 
     @_oracle_char_combinations
-    @testing.requires.python3
-    def test_no_encoding_errors_cx_oracle_py3k(
+    def test_no_encoding_errors_cx_oracle(
         self,
         cx_Oracle,
         cx_oracle_type,
index 70b00c06f206fdaf70fe24f4ee6d90f4da054f24..2b54f2b56c7370cc909f818ca1f8bf43a28b46a0 100644 (file)
@@ -48,7 +48,6 @@ from sqlalchemy.testing.engines import testing_engine
 from sqlalchemy.testing.schema import Column
 from sqlalchemy.testing.schema import Table
 from sqlalchemy.util import b
-from sqlalchemy.util import py2k
 from sqlalchemy.util import u
 
 
@@ -202,11 +201,7 @@ class TypesTest(fixtures.TestBase):
             Column("id", Integer, primary_key=True),
             Column("data", char_type(30), nullable=False),
         )
-
-        if py2k and char_type is NCHAR:
-            v1, v2, v3 = u"value 1", u"value 2", u"value 3"
-        else:
-            v1, v2, v3 = "value 1", "value 2", "value 3"
+        v1, v2, v3 = "value 1", "value 2", "value 3"
 
         t.create(connection)
         connection.execute(
@@ -719,17 +714,14 @@ class TypesTest(fixtures.TestBase):
 
             eq_(sqla_result, cx_oracle_result)
 
-    @testing.only_on("oracle+cx_oracle", "cx_oracle-specific feature")
-    @testing.fails_if(
-        testing.requires.python3, "cx_oracle always returns unicode on py3k"
-    )
     def test_coerce_to_unicode(self, connection):
         engine = testing_engine(options=dict(coerce_to_unicode=False))
         with engine.connect() as conn_no_coerce:
             value = exec_sql(
                 conn_no_coerce, "SELECT 'hello' FROM DUAL"
             ).scalar()
-            assert isinstance(value, util.binary_type)
+            assert not isinstance(value, util.binary_type)
+            assert isinstance(value, util.text_type)
 
         value = exec_sql(connection, "SELECT 'hello' FROM DUAL").scalar()
         assert isinstance(value, util.text_type)
index c0eb4410cf972fd3dd92312788df304977ab8e0d..6e665c71ba583f20f6a42f09657f02f1aec42eff 100644 (file)
@@ -35,7 +35,6 @@ from sqlalchemy.dialects.postgresql.psycopg2 import EXECUTEMANY_BATCH
 from sqlalchemy.dialects.postgresql.psycopg2 import EXECUTEMANY_PLAIN
 from sqlalchemy.dialects.postgresql.psycopg2 import EXECUTEMANY_VALUES
 from sqlalchemy.engine import cursor as _cursor
-from sqlalchemy.engine import engine_from_config
 from sqlalchemy.engine import url
 from sqlalchemy.sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
 from sqlalchemy.testing import config
@@ -163,44 +162,14 @@ $$ LANGUAGE plpgsql;"""
             future_connection.dialect.server_version_info,
         )
 
-    @testing.requires.python3
     @testing.requires.psycopg2_compatibility
-    def test_pg_dialect_no_native_unicode_in_python3(self, testing_engine):
+    def test_pg_dialect_no_native_unicode_in(self, testing_engine):
         with testing.expect_raises_message(
             exc.ArgumentError,
             "psycopg2 native_unicode mode is required under Python 3",
         ):
             testing_engine(options=dict(use_native_unicode=False))
 
-    @testing.requires.python2
-    @testing.requires.psycopg2_compatibility
-    def test_pg_dialect_no_native_unicode_in_python2(self, testing_engine):
-        e = testing_engine(options=dict(use_native_unicode=False))
-        with e.connect() as conn:
-            eq_(
-                conn.exec_driver_sql(u"SELECT '🐍 voix m’a réveillé'").scalar(),
-                u"🐍 voix m’a réveillé".encode("utf-8"),
-            )
-
-    @testing.requires.python2
-    @testing.requires.psycopg2_compatibility
-    def test_pg_dialect_use_native_unicode_from_config(self):
-        config = {
-            "sqlalchemy.url": testing.db.url,
-            "sqlalchemy.use_native_unicode": "false",
-        }
-
-        e = engine_from_config(config, _initialize=False)
-        eq_(e.dialect.use_native_unicode, False)
-
-        config = {
-            "sqlalchemy.url": testing.db.url,
-            "sqlalchemy.use_native_unicode": "true",
-        }
-
-        e = engine_from_config(config, _initialize=False)
-        eq_(e.dialect.use_native_unicode, True)
-
     def test_psycopg2_empty_connection_string(self):
         dialect = psycopg2_dialect.dialect()
         u = url.make_url("postgresql://")
index e5f0277909537b7e98fb80f6e777ec8b95e4ee9d..ebb4d4b1257a5bdf5ffdd338777ea553981141f9 100644 (file)
@@ -2403,7 +2403,6 @@ class ArrayEnum(fixtures.TestBase):
         eq_(connection.execute(sel).fetchall(), [(["foo", "bar"],)])
 
     @_enum_combinations
-    @testing.requires.python3
     def test_array_of_enums_native_roundtrip(
         self, array_of_enum_fixture, connection, array_cls, enum_cls
     ):
index ed0f11907cfe62da32e2f2752ce619493b285d9b..eb68c0c6f2dc176c0c5304eedcc25194c29c816a 100644 (file)
@@ -597,7 +597,6 @@ class DialectTest(
                 )
             )
 
-    @testing.requires.insert_order_dicts
     @testing.only_on("sqlite+pysqlite")
     def test_isolation_level_message(self):
         # needs to test that all three words are present and we also
@@ -714,9 +713,6 @@ class DialectTest(
 
     @testing.provide_metadata
     def test_description_encoding(self, connection):
-        # amazingly, pysqlite seems to still deliver cursor.description
-        # as encoded bytes in py2k
-
         t = Table(
             "x",
             self.metadata,
index 91cc60fc7bcd5897ac14f5b6f24f75e08e4647cf..7ee4c17c5854354ca24cab0a0cafb196c45c88cf 100644 (file)
@@ -391,15 +391,8 @@ class ExecuteTest(fixtures.TablesTest):
         with testing.db.connect() as conn:
             assert_raises_message(
                 tsa.exc.StatementError,
-                util.u(
-                    "A value is required for bind parameter 'uname'\n"
-                    r".*SELECT users.user_name AS .m\xe9il."
-                )
-                if util.py2k
-                else util.u(
-                    "A value is required for bind parameter 'uname'\n"
-                    ".*SELECT users.user_name AS .méil."
-                ),
+                "A value is required for bind parameter 'uname'\n"
+                ".*SELECT users.user_name AS .méil.",
                 conn.execute,
                 select(users.c.user_name.label(name)).where(
                     users.c.user_name == bindparam("uname")
@@ -413,14 +406,7 @@ class ExecuteTest(fixtures.TablesTest):
         message = util.u("some message méil").encode("utf-8")
 
         err = tsa.exc.SQLAlchemyError(message)
-        if util.py2k:
-            # string passes it through
-            eq_(str(err), message)
-
-            # unicode accessor decodes to utf-8
-            eq_(unicode(err), util.u("some message méil"))  # noqa F821
-        else:
-            eq_(str(err), util.u("some message méil"))
+        eq_(str(err), util.u("some message méil"))
 
     def test_stmt_exception_bytestring_latin1(self):
         # uncommon case for Py3K, bytestring object passed
@@ -428,14 +414,7 @@ class ExecuteTest(fixtures.TablesTest):
         message = util.u("some message méil").encode("latin-1")
 
         err = tsa.exc.SQLAlchemyError(message)
-        if util.py2k:
-            # string passes it through
-            eq_(str(err), message)
-
-            # unicode accessor decodes to utf-8
-            eq_(unicode(err), util.u("some message m\\xe9il"))  # noqa F821
-        else:
-            eq_(str(err), util.u("some message m\\xe9il"))
+        eq_(str(err), util.u("some message m\\xe9il"))
 
     def test_stmt_exception_unicode_hook_unicode(self):
         # uncommon case for Py2K, Unicode object passed
@@ -443,18 +422,12 @@ class ExecuteTest(fixtures.TablesTest):
         message = util.u("some message méil")
 
         err = tsa.exc.SQLAlchemyError(message)
-        if util.py2k:
-            eq_(unicode(err), util.u("some message méil"))  # noqa F821
-        else:
-            eq_(str(err), util.u("some message méil"))
+        eq_(str(err), util.u("some message méil"))
 
     def test_stmt_exception_object_arg(self):
         err = tsa.exc.SQLAlchemyError(Foo())
         eq_(str(err), "foo")
 
-        if util.py2k:
-            eq_(unicode(err), util.u("fóó"))  # noqa F821
-
     def test_stmt_exception_str_multi_args(self):
         err = tsa.exc.SQLAlchemyError("some message", 206)
         eq_(str(err), "('some message', 206)")
@@ -731,8 +704,7 @@ class ExecuteTest(fixtures.TablesTest):
 
 
 class UnicodeReturnsTest(fixtures.TestBase):
-    @testing.requires.python3
-    def test_unicode_test_not_in_python3(self):
+    def test_unicode_test_not_in(self):
         eng = engines.testing_engine()
         eng.dialect.returns_unicode_strings = String.RETURNS_UNKNOWN
 
@@ -742,25 +714,6 @@ class UnicodeReturnsTest(fixtures.TestBase):
             eng.connect,
         )
 
-    @testing.requires.python2
-    def test_unicode_test_fails_warning(self):
-        class MockCursor(engines.DBAPIProxyCursor):
-            def execute(self, stmt, params=None, **kw):
-                if "test unicode returns" in stmt:
-                    raise self.engine.dialect.dbapi.DatabaseError("boom")
-                else:
-                    return super(MockCursor, self).execute(stmt, params, **kw)
-
-        eng = engines.proxying_engine(cursor_cls=MockCursor)
-        with testing.expect_warnings(
-            "Exception attempting to detect unicode returns"
-        ):
-            eng.connect()
-
-        # because plain varchar passed, we don't know the correct answer
-        eq_(eng.dialect.returns_unicode_strings, String.RETURNS_CONDITIONAL)
-        eng.dispose()
-
 
 class ConvenienceExecuteTest(fixtures.TablesTest):
     __backend__ = True
index d24654f445fc5d084550d960dc59c7f9277e90a1..0cc7c0508d08489f98eca2bcdc69ee31d5a2c608 100644 (file)
@@ -389,7 +389,6 @@ class URLTest(fixtures.TestBase):
             ),
         )
 
-    @testing.requires.python3
     def test_arg_validation_all_seven_posn(self):
         """test #7130"""
         with testing.expect_deprecated(
index 43ec9cc3ffaccfafbb5e607f5c44d85fc11e9235..1c730334aa37f4db58622b3124d91d14fb17b70a 100644 (file)
@@ -744,7 +744,7 @@ class PoolEventsTest(PoolTestBase):
         assert canary.call_args_list[0][0][0] is dbapi_con
         assert canary.call_args_list[0][0][2] is exc
 
-    @testing.combinations((True, testing.requires.python3), (False,))
+    @testing.combinations((True,), (False,))
     def test_checkin_event_gc(self, detach_gced):
         p, canary = self._checkin_event_fixture(_is_asyncio=detach_gced)
 
@@ -1634,7 +1634,7 @@ class QueuePoolTest(PoolTestBase):
 
         self._assert_cleanup_on_pooled_reconnect(dbapi, p)
 
-    @testing.combinations((True, testing.requires.python3), (False,))
+    @testing.combinations((True,), (False,))
     def test_userspace_disconnectionerror_weakref_finalizer(self, detach_gced):
         dbapi, pool = self._queuepool_dbapi_fixture(
             pool_size=1, max_overflow=2, _is_asyncio=detach_gced
index 3c260f9e5d948128f185713d994c0b4a0a9c9c4c..44cf9388ca08b0c0ba8b164405763d6c9924bc46 100644 (file)
@@ -232,7 +232,6 @@ class AsyncEngineTest(EngineFixture):
         is_false(async_engine == None)
 
     @async_test
-    @testing.requires.python37
     async def test_no_attach_to_event_loop(self, testing_engine):
         """test #6409"""
 
index 065dc7442c81e8615cdc9b469d63662a88f665a2..d722320f3e341e16a12cf818101fd7c4b585d97d 100644 (file)
@@ -1,7 +1,6 @@
 import sqlalchemy as sa
 from sqlalchemy import func
 from sqlalchemy import select
-from sqlalchemy import testing
 from sqlalchemy.ext.asyncio import async_scoped_session
 from sqlalchemy.ext.asyncio import AsyncSession as _AsyncSession
 from sqlalchemy.orm import sessionmaker
@@ -12,7 +11,6 @@ from .test_session_py3k import AsyncFixture
 
 
 class AsyncScopedSessionTest(AsyncFixture):
-    @testing.requires.python37
     @async_test
     async def test_basic(self, async_engine):
         from asyncio import current_task
@@ -46,7 +44,6 @@ class AsyncScopedSessionTest(AsyncFixture):
             await AsyncSession.flush()
             eq_(await conn.scalar(stmt), 0)
 
-    @testing.requires.python37
     def test_attributes(self, async_engine):
         from asyncio import current_task
 
index a405b9f2c6a93c7e7d2c21743e3ce60c234fe633..0e3a48458b3a88315160e15e7ccdeb41604fe88d 100644 (file)
@@ -469,22 +469,21 @@ class DeclarativeTest(DeclarativeTestBase):
         ][0]
         is_(ck.columns.cprop, Bar.__table__.c.cprop)
 
-        if testing.requires.python3.enabled:
-            # test the existing failure case in case something changes
-            def go():
-                class Bat(Base):
-                    __tablename__ = "bat"
+        # test the existing failure case in case something changes
+        def go():
+            class Bat(Base):
+                __tablename__ = "bat"
 
-                    id = Column(Integer, primary_key=True)
-                    cprop = deferred(Column(Integer))
+                id = Column(Integer, primary_key=True)
+                cprop = deferred(Column(Integer))
 
-                    # we still can't do an expression like
-                    # "cprop > 5" because the column property isn't
-                    # a full blown column
+                # we still can't do an expression like
+                # "cprop > 5" because the column property isn't
+                # a full blown column
 
-                    __table_args__ = (CheckConstraint(cprop > 5),)
+                __table_args__ = (CheckConstraint(cprop > 5),)
 
-            assert_raises(TypeError, go)
+        assert_raises(TypeError, go)
 
     def test_relationship_level_msg_for_invalid_callable(self):
         class A(Base):
@@ -2326,7 +2325,6 @@ class DeclarativeTest(DeclarativeTestBase):
         mt = MyTable(id=5)
         eq_(mt.id, 5)
 
-    @testing.requires.python36
     def test_kw_support_in_declarative_meta_init(self):
         # This will not fail if DeclarativeMeta __init__ supports **kw
 
index 3473dcf50bfb879ee84cc337a0edc6aa90f038cb..90bb606cbcbeef006f562ecd3a463fb987a7bedd 100644 (file)
@@ -80,12 +80,7 @@ class Canary(object):
 class OrderedDictFixture(object):
     @testing.fixture
     def ordered_dict_mro(self):
-        if testing.requires.python37.enabled:
-            return type("ordered", (collections.MappedCollection,), {})
-        else:
-            return type(
-                "ordered", (util.OrderedDict, collections.MappedCollection), {}
-            )
+        return type("ordered", (collections.MappedCollection,), {})
 
 
 class CollectionsTest(OrderedDictFixture, fixtures.ORMTest):
index a9b0ba58dfcd67491c6b530649f77343746f8087..706024eb5e0fb962be6d9d17ab13dafe8fa06958 100644 (file)
@@ -26,8 +26,6 @@ except ImportError:
 
 
 class DataclassesTest(fixtures.MappedTest, testing.AssertsCompiledSQL):
-    __requires__ = ("dataclasses",)
-
     @classmethod
     def define_tables(cls, metadata):
         Table(
@@ -232,8 +230,6 @@ class DataclassesTest(fixtures.MappedTest, testing.AssertsCompiledSQL):
 
 
 class PlainDeclarativeDataclassesTest(DataclassesTest):
-    __requires__ = ("dataclasses",)
-
     run_setup_classes = "each"
     run_setup_mappers = "each"
 
@@ -296,8 +292,6 @@ class PlainDeclarativeDataclassesTest(DataclassesTest):
 class FieldEmbeddedDeclarativeDataclassesTest(
     fixtures.DeclarativeMappedTest, DataclassesTest
 ):
-    __requires__ = ("dataclasses",)
-
     @classmethod
     def setup_classes(cls):
         declarative = cls.DeclarativeBasic.registry.mapped
@@ -391,8 +385,6 @@ class FieldEmbeddedDeclarativeDataclassesTest(
 
 
 class FieldEmbeddedWMixinTest(FieldEmbeddedDeclarativeDataclassesTest):
-    __requires__ = ("dataclasses",)
-
     @classmethod
     def setup_classes(cls):
         declarative = cls.DeclarativeBasic.registry.mapped
@@ -521,8 +513,6 @@ class FieldEmbeddedWMixinTest(FieldEmbeddedDeclarativeDataclassesTest):
 
 
 class FieldEmbeddedMixinWLambdaTest(fixtures.DeclarativeMappedTest):
-    __requires__ = ("dataclasses",)
-
     @classmethod
     def setup_classes(cls):
         declarative = cls.DeclarativeBasic.registry.mapped
@@ -699,8 +689,6 @@ class FieldEmbeddedMixinWLambdaTest(fixtures.DeclarativeMappedTest):
 
 
 class FieldEmbeddedMixinWDeclaredAttrTest(FieldEmbeddedMixinWLambdaTest):
-    __requires__ = ("dataclasses",)
-
     @classmethod
     def setup_classes(cls):
         declarative = cls.DeclarativeBasic.registry.mapped
@@ -840,8 +828,6 @@ class FieldEmbeddedMixinWDeclaredAttrTest(FieldEmbeddedMixinWLambdaTest):
 
 
 class PropagationFromMixinTest(fixtures.TestBase):
-    __requires__ = ("dataclasses",)
-
     def test_propagate_w_plain_mixin_col(self, run_test):
         @dataclasses.dataclass
         class CommonMixin:
@@ -940,8 +926,6 @@ class PropagationFromMixinTest(fixtures.TestBase):
 
 
 class PropagationFromAbstractTest(fixtures.TestBase):
-    __requires__ = ("dataclasses",)
-
     def test_propagate_w_plain_mixin_col(self, run_test):
         @dataclasses.dataclass
         class BaseType:
index deb196897506ebc280ba53d01287ec5aa2c29f7c..061cad7e3b7260d43cc8a86a1005c4748d1200dd 100644 (file)
@@ -6310,53 +6310,6 @@ class RequirementsTest(fixtures.MappedTest):
             Column("value", String(10)),
         )
 
-    if util.py2k:
-
-        def test_baseclass_map_imperatively(self):
-            ht1 = self.tables.ht1
-
-            class OldStyle:
-                pass
-
-            assert_raises(
-                sa.exc.ArgumentError,
-                self.mapper_registry.map_imperatively,
-                OldStyle,
-                ht1,
-            )
-
-            assert_raises(
-                sa.exc.ArgumentError,
-                self.mapper_registry.map_imperatively,
-                123,
-            )
-
-        def test_baseclass_legacy_mapper(self):
-            ht1 = self.tables.ht1
-
-            class OldStyle:
-                pass
-
-            assert_raises(
-                sa.exc.ArgumentError,
-                mapper,
-                OldStyle,
-                ht1,
-            )
-
-            assert_raises(
-                sa.exc.ArgumentError,
-                mapper,
-                123,
-            )
-
-            class NoWeakrefSupport(str):
-                pass
-
-            # TODO: is weakref support detectable without an instance?
-            # self.assertRaises(
-            #  sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2)
-
 
 class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest):
     __dialect__ = "default"
index 3cc7640cf03d15449347a377d687d5312d1d0b97..0917544cb61225bf69b15bf4a9a7207978bfb7f1 100644 (file)
@@ -515,7 +515,6 @@ class %s(SuperCls):
         exec(code, glbls)
         return names, glbls[clsname]
 
-    @testing.requires.pep520
     def test_all_orm_descriptors_pep520_noinh(self):
         from sqlalchemy.orm import declarative_base
 
@@ -528,7 +527,6 @@ class %s(SuperCls):
 
         eq_(MyClass.__mapper__.all_orm_descriptors.keys(), names)
 
-    @testing.requires.pep520
     def test_all_orm_descriptors_pep520_onelevel_inh(self):
         from sqlalchemy.orm import declarative_base
 
@@ -549,7 +547,6 @@ class %s(SuperCls):
             sub_names + base_names,
         )
 
-    @testing.requires.pep520
     def test_all_orm_descriptors_pep520_classical(self):
         class MyClass(object):
             pass
index a2d4aa9cac23c31f24262e796274aeb477bdd9bd..9158b51151eab042cd12a78870a4f91843754453 100644 (file)
@@ -613,8 +613,6 @@ class NativeInstrumentationTest(fixtures.MappedTest):
 
 
 class Py3KFunctionInstTest(fixtures.ORMTest):
-    __requires__ = ("python3",)
-
     def _instrument(self, cls):
         manager = instrumentation.register_class(cls)
         canary = []
index 4d620ac489056a0c5dbe1ad2e44fce0ea914c4d6..ec1ef37962756f4e8e95ba1064146a9cd4e5e3bf 100644 (file)
@@ -415,11 +415,7 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
         m = self.mapper(Foo, foo_t)
 
         class DontCompareMeToString(int):
-            if util.py2k:
-
-                def __lt__(self, other):
-                    assert not isinstance(other, basestring)  # noqa
-                    return int(self) < other
+            pass
 
         foos = [Foo(id_="f%d" % i) for i in range(5)]
         states = [attributes.instance_state(f) for f in foos]
index 29ba24b1bfd632a56502a6360953f1dd55dcff1f..b8269d76d5e0d3fc1f86ea4386ff12d23504df2b 100644 (file)
@@ -1675,7 +1675,6 @@ class OperatorTest(QueryTest, AssertsCompiledSQL):
         (operators.mul, "*"),
         (operators.sub, "-"),
         (operators.truediv, "/"),
-        (operators.div, "/"),
         argnames="py_op, sql_op",
         id_="ar",
     )
index 87f0a2aae897d003a5ca7757cf90fb8d8a2163ef..1558da65524d5b0dd62695634de1c896140443d3 100644 (file)
@@ -168,8 +168,8 @@ class ScopedSessionTest(fixtures.MappedTest):
         eq_(mock_object_session.mock_calls, [mock.call("foo")])
 
     @testing.combinations(
-        ("style1", testing.requires.python3),
-        ("style2", testing.requires.python3),
+        "style1",
+        "style2",
         "style3",
         "style4",
     )
index b7062cf42798261ce204ad0839dfec13d4f1db37..64cac988b84b359ec3d758c079963357a982086c 100644 (file)
@@ -860,33 +860,6 @@ class SessionTransactionTest(fixtures.RemovesEvents, FixtureTest):
         # new in 1.4
         is_(session._legacy_transaction(), None)
 
-    @testing.requires.python2
-    @testing.requires.savepoints_w_release
-    def test_report_primary_error_when_rollback_fails(self):
-        User, users = self.classes.User, self.tables.users
-
-        self.mapper_registry.map_imperatively(User, users)
-
-        with fixture_session() as session:
-
-            with expect_warnings(
-                ".*during handling of a previous exception.*"
-            ):
-                session.begin_nested()
-                savepoint = session.connection()._nested_transaction._savepoint
-
-                # force the savepoint to disappear
-                session.connection().dialect.do_release_savepoint(
-                    session.connection(), savepoint
-                )
-
-                # now do a broken flush
-                session.add_all([User(id=1), User(id=1)])
-
-                assert_raises_message(
-                    sa_exc.DBAPIError, "ROLLBACK TO SAVEPOINT ", session.flush
-                )
-
 
 class _LocalFixture(FixtureTest):
     run_setup_mappers = "once"
index 2db7a5744648b377abce5de833f7429ee308b5aa..8ec88a760b47d5995ac41b134643fc7e62c6b6ce 100644 (file)
@@ -1592,7 +1592,7 @@ class CompareClausesTest(fixtures.TestBase):
         )
 
         l2 = ClauseList(
-            table_c.c.x, table_c.c.y, table_d.c.y, operator=operators.div
+            table_c.c.x, table_c.c.y, table_d.c.y, operator=operators.truediv
         )
 
         is_false(l1.compare(l2))
index c001dc4ef3eaf78ded4d6a287ba9f2aff2e446a4..3bb097714b19400818c3c92ec83296bbe82c2609 100644 (file)
@@ -2184,7 +2184,7 @@ class MathOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
         ("add", operator.add, "+"),
         ("mul", operator.mul, "*"),
         ("sub", operator.sub, "-"),
-        ("div", operator.truediv if util.py3k else operator.div, "/"),
+        ("div", operator.truediv, "/"),
         ("mod", operator.mod, "%"),
         id_="iaa",
     )
@@ -3245,7 +3245,6 @@ class TupleTypingTest(fixtures.TestBase):
         self._assert_types(expr.right.type.types)
 
     # since we want to infer "binary"
-    @testing.requires.python3
     def test_tuple_type_expanding_inference(self):
         a, b, c = column("a"), column("b"), column("c")
 
@@ -3256,7 +3255,6 @@ class TupleTypingTest(fixtures.TestBase):
 
         self._assert_types(expr.right.type.types)
 
-    @testing.requires.python3
     def test_tuple_type_plain_inference(self):
         a, b, c = column("a"), column("b"), column("c")
 
index e51bdf5a06128b75514d035698ac140fb6e5c43d..67954d9ce40defb839471a0d1621f1ce8ca1b94c 100644 (file)
@@ -13,7 +13,6 @@ from sqlalchemy import select
 from sqlalchemy import sql
 from sqlalchemy import Table
 from sqlalchemy import testing
-from sqlalchemy import util
 from sqlalchemy.engine import default
 from sqlalchemy.sql import compiler
 from sqlalchemy.sql import LABEL_STYLE_TABLENAME_PLUS_COL
@@ -251,10 +250,7 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL):
     def test_repr_unicode(self):
         name = quoted_name(u"姓名", None)
 
-        if util.py2k:
-            eq_(repr(name), "'\u59d3\u540d'")
-        else:
-            eq_(repr(name), repr(u"姓名"))
+        eq_(repr(name), repr(u"姓名"))
 
     def test_lower_case_names(self):
         # Create table with quote defaults
index 47f26ddab3b9f3e682a1192e87cbbc5f5f22e37d..86aa15f26ff80867c8ca84f908e06190f67e760d 100644 (file)
@@ -1139,7 +1139,6 @@ class CursorResultTest(fixtures.TablesTest):
             eq_(row._mapping[s.c.user_id], 7)
             eq_(row._mapping[s.c.user_name], "ed")
 
-    @testing.requires.python3
     def test_ro_mapping_py3k(self, connection):
         users = self.tables.users
 
@@ -1162,27 +1161,6 @@ class CursorResultTest(fixtures.TablesTest):
         eq_(odict_row.values(), mapping_row.values())
         eq_(odict_row.items(), mapping_row.items())
 
-    @testing.requires.python2
-    def test_ro_mapping_py2k(self, connection):
-        users = self.tables.users
-
-        connection.execute(users.insert(), dict(user_id=1, user_name="foo"))
-        result = connection.execute(users.select())
-
-        row = result.first()
-        dict_row = row._asdict()
-
-        odict_row = collections.OrderedDict(
-            [("user_id", 1), ("user_name", "foo")]
-        )
-        eq_(dict_row, odict_row)
-        mapping_row = row._mapping
-
-        eq_(list(mapping_row), list(mapping_row.keys()))
-        eq_(odict_row.keys(), list(mapping_row.keys()))
-        eq_(odict_row.values(), list(mapping_row.values()))
-        eq_(odict_row.items(), list(mapping_row.items()))
-
     @testing.combinations(
         (lambda result: result),
         (lambda result: result.first(),),