MOTOR-614 Use Python 3 syntax for super() calls (#89)
This commit is contained in:
parent
ca6141cb6d
commit
ed02ce5e75
@ -6,7 +6,7 @@ from sphinx import addnodes
|
||||
|
||||
class PyCoroutineMixin(object):
|
||||
def handle_signature(self, sig, signode):
|
||||
ret = super(PyCoroutineMixin, self).handle_signature(sig, signode)
|
||||
ret = super().handle_signature(sig, signode)
|
||||
signode.insert(0, addnodes.desc_annotation('coroutine ', 'coroutine '))
|
||||
return ret
|
||||
|
||||
|
||||
@ -29,10 +29,10 @@ class Application(tornado.web.Application):
|
||||
templates = os.path.join(os.path.dirname(__file__),
|
||||
"tornado_change_stream_templates")
|
||||
|
||||
super(Application, self).__init__(handlers,
|
||||
template_path=templates,
|
||||
template_whitespace="all",
|
||||
debug=options.debug)
|
||||
super().__init__(handlers,
|
||||
template_path=templates,
|
||||
template_whitespace="all",
|
||||
debug=options.debug)
|
||||
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
|
||||
@ -89,7 +89,7 @@ class ContextualZipFile(zipfile.ZipFile):
|
||||
"""Construct a ZipFile or ContextualZipFile as appropriate."""
|
||||
if hasattr(zipfile.ZipFile, '__exit__'):
|
||||
return zipfile.ZipFile(*args, **kwargs)
|
||||
return super(ContextualZipFile, cls).__new__(cls)
|
||||
return super().__new__(cls)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
@ -154,7 +154,7 @@ class AgnosticClient(AgnosticBaseProperties):
|
||||
DriverInfo('Motor', motor_version, self._framework.platform_info()))
|
||||
|
||||
delegate = self.__delegate_class__(*args, **kwargs)
|
||||
super(AgnosticBaseProperties, self).__init__(delegate)
|
||||
super().__init__(delegate)
|
||||
self.io_loop = io_loop
|
||||
|
||||
def get_io_loop(self):
|
||||
@ -516,7 +516,7 @@ class AgnosticDatabase(AgnosticBaseProperties):
|
||||
delegate = kwargs.get('_delegate') or Database(
|
||||
client.delegate, name, **kwargs)
|
||||
|
||||
super(self.__class__, self).__init__(delegate)
|
||||
super().__init__(delegate)
|
||||
|
||||
def aggregate(self, pipeline, **kwargs):
|
||||
"""Execute an aggregation pipeline on this database.
|
||||
@ -736,7 +736,7 @@ class AgnosticCollection(AgnosticBaseProperties):
|
||||
read_preference=read_preference, write_concern=write_concern,
|
||||
read_concern=read_concern)
|
||||
|
||||
super(self.__class__, self).__init__(delegate)
|
||||
super().__init__(delegate)
|
||||
self.database = database
|
||||
|
||||
def __getattr__(self, name):
|
||||
@ -1096,7 +1096,7 @@ class AgnosticBaseCursor(AgnosticBase):
|
||||
cleaned up by the garbage collector.
|
||||
"""
|
||||
# 'cursor' is a PyMongo Cursor, CommandCursor, or a _LatentCursor.
|
||||
super(AgnosticBaseCursor, self).__init__(delegate=cursor)
|
||||
super().__init__(delegate=cursor)
|
||||
self.collection = collection
|
||||
self.started = False
|
||||
self.closed = False
|
||||
@ -1575,7 +1575,7 @@ class AgnosticLatentCommandCursor(AgnosticCommandCursor):
|
||||
# a PyMongo CommandCursor back yet. Set self.delegate to a latent
|
||||
# cursor until the first await triggers _get_more(), which
|
||||
# will execute the callback "start", which gets a PyMongo CommandCursor.
|
||||
super(self.__class__, self).__init__(_LatentCursor(), collection)
|
||||
super().__init__(_LatentCursor(), collection)
|
||||
self.start = start
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
@ -1601,7 +1601,7 @@ class AgnosticLatentCommandCursor(AgnosticCommandCursor):
|
||||
|
||||
return original_future
|
||||
|
||||
return super(self.__class__, self)._get_more()
|
||||
return super()._get_more()
|
||||
|
||||
def _on_started(self, original_future, future):
|
||||
try:
|
||||
@ -1623,7 +1623,7 @@ class AgnosticLatentCommandCursor(AgnosticCommandCursor):
|
||||
len(self.delegate._CommandCursor__data))
|
||||
else:
|
||||
# Send a getMore.
|
||||
future = super(self.__class__, self)._get_more()
|
||||
future = super()._get_more()
|
||||
self._framework.chain_future(future, original_future)
|
||||
|
||||
|
||||
@ -1647,7 +1647,7 @@ class AgnosticChangeStream(AgnosticBase):
|
||||
def __init__(self, target, pipeline, full_document, resume_after,
|
||||
max_await_time_ms, batch_size, collation,
|
||||
start_at_operation_time, session, start_after):
|
||||
super(self.__class__, self).__init__(delegate=None)
|
||||
super().__init__(delegate=None)
|
||||
# The "target" object is a client, database, or collection.
|
||||
self._target = target
|
||||
self._kwargs = {'pipeline': pipeline,
|
||||
|
||||
@ -145,7 +145,7 @@ class Async(MotorAttributeFactory):
|
||||
- `attr_name`: The name of the attribute on the PyMongo class, if
|
||||
different from attribute on the Motor class
|
||||
"""
|
||||
super(Async, self).__init__(doc)
|
||||
super().__init__(doc)
|
||||
self.attr_name = attr_name
|
||||
self.wrap_class = None
|
||||
self.unwrap_class = None
|
||||
@ -271,14 +271,7 @@ def create_class_with_framework(cls, framework, module_name):
|
||||
if cached_class:
|
||||
return cached_class
|
||||
|
||||
# Remove the special __dict__ proxy and let type() create it instead,
|
||||
# otherwise attempting to access cls().__dict__ will raise a TypeError:
|
||||
# TypeError: descriptor '__dict__' for 'AgnosticGridIn' objects doesn't
|
||||
# apply to 'MotorGridIn' object.
|
||||
cls_dict = dict(cls.__dict__)
|
||||
cls_dict.pop('__dict__', None)
|
||||
|
||||
new_class = type(str(motor_class_name), cls.__bases__, cls_dict)
|
||||
new_class = type(str(motor_class_name), (cls,), {})
|
||||
new_class.__module__ = module_name
|
||||
new_class._framework = framework
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ class AgnosticGridOutCursor(AgnosticCursor):
|
||||
|
||||
def next_object(self):
|
||||
"""**DEPRECATED** - Get next GridOut object from cursor."""
|
||||
grid_out = super(self.__class__, self).next_object()
|
||||
grid_out = super().next_object()
|
||||
if grid_out:
|
||||
grid_out_class = create_class_with_framework(
|
||||
AgnosticGridOut, self._framework, self.__module__)
|
||||
|
||||
@ -626,10 +626,10 @@ class GridOutCursor(Cursor):
|
||||
raise TypeError(
|
||||
"Expected MotorGridOutCursor, got %r" % delegate)
|
||||
|
||||
super(GridOutCursor, self).__init__(delegate)
|
||||
super().__init__(delegate)
|
||||
|
||||
def next(self):
|
||||
motor_grid_out = super(GridOutCursor, self).next()
|
||||
motor_grid_out = super().next()
|
||||
if motor_grid_out:
|
||||
return GridOut(self.collection, delegate=motor_grid_out)
|
||||
|
||||
@ -739,7 +739,7 @@ class GridOut(Synchro):
|
||||
"upload_date", "aliases", "metadata", "md5"):
|
||||
raise AttributeError()
|
||||
|
||||
super(GridOut, self).__setattr__(key, value)
|
||||
super().__setattr__(key, value)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
@ -234,10 +234,10 @@ class SynchroNosePlugin(Plugin):
|
||||
# We need a standard Nose selector in order to filter out methods that
|
||||
# don't match TestSuite.test_*
|
||||
self.selector = Selector(config=None)
|
||||
super(SynchroNosePlugin, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def configure(self, options, conf):
|
||||
super(SynchroNosePlugin, self).configure(options, conf)
|
||||
super().configure(options, conf)
|
||||
self.enabled = True
|
||||
|
||||
def wantModule(self, module):
|
||||
|
||||
@ -55,7 +55,7 @@ class SkippedModule(object):
|
||||
|
||||
class MotorTestLoader(unittest.TestLoader):
|
||||
def __init__(self, avoid=None, reason=None):
|
||||
super(MotorTestLoader, self).__init__()
|
||||
super().__init__()
|
||||
self._avoid = []
|
||||
|
||||
def avoid(self, *prefixes, **kwargs):
|
||||
@ -75,7 +75,7 @@ class MotorTestLoader(unittest.TestLoader):
|
||||
if name.startswith(prefix):
|
||||
return SkippedModule(name, reason)
|
||||
|
||||
return super(MotorTestLoader, self)._get_module_from_name(name)
|
||||
return super()._get_module_from_name(name)
|
||||
|
||||
|
||||
class MockRequestHandler(object):
|
||||
|
||||
@ -82,7 +82,7 @@ class AsyncIOTestCase(AssertLogsMixin, unittest.TestCase):
|
||||
getattr(self, methodName)))
|
||||
|
||||
def setUp(self):
|
||||
super(AsyncIOTestCase, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
# Ensure that the event loop is passed explicitly in Motor.
|
||||
asyncio.set_event_loop(None)
|
||||
|
||||
@ -130,3 +130,26 @@ class AIOMotorTestBasic(AsyncIOTestCase):
|
||||
# MOTOR-104, TypeError: Can't instantiate abstract class C with abstract
|
||||
# methods collection, db, subcollection.
|
||||
C()
|
||||
|
||||
@asyncio_test
|
||||
async def test_inheritance(self):
|
||||
class CollectionSubclass(motor_asyncio.AsyncIOMotorCollection):
|
||||
pass
|
||||
|
||||
class DatabaseSubclass(motor_asyncio.AsyncIOMotorDatabase):
|
||||
def __getitem__(self, name):
|
||||
return CollectionSubclass(self, name)
|
||||
|
||||
class ClientSubclass(motor_asyncio.AsyncIOMotorClient):
|
||||
def __getitem__(self, name):
|
||||
return DatabaseSubclass(self, name)
|
||||
|
||||
cx = ClientSubclass(test.env.uri, **self.get_client_kwargs())
|
||||
self.assertIsInstance(cx, ClientSubclass)
|
||||
|
||||
db = cx['testdb']
|
||||
self.assertIsInstance(db, DatabaseSubclass)
|
||||
|
||||
coll = db['testcoll']
|
||||
self.assertIsInstance(coll, CollectionSubclass)
|
||||
self.assertIsNotNone(await coll.insert_one({}))
|
||||
|
||||
@ -30,7 +30,7 @@ class TestAsyncIOChangeStream(AsyncIOTestCase):
|
||||
@classmethod
|
||||
@env.require_version_min(3, 6)
|
||||
def setUpClass(cls):
|
||||
super(TestAsyncIOChangeStream, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
if env.is_standalone:
|
||||
raise SkipTest("Standalone")
|
||||
|
||||
|
||||
@ -540,12 +540,12 @@ class TestAsyncIOCursor(AsyncIOMockServerTestCase):
|
||||
|
||||
class TestAsyncIOCursorMaxTimeMS(AsyncIOTestCase):
|
||||
def setUp(self):
|
||||
super(TestAsyncIOCursorMaxTimeMS, self).setUp()
|
||||
super().setUp()
|
||||
self.loop.run_until_complete(self.maybe_skip())
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.run_until_complete(self.disable_timeout())
|
||||
super(TestAsyncIOCursorMaxTimeMS, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
async def maybe_skip(self):
|
||||
if (await server_is_mongos(self.cx)):
|
||||
|
||||
@ -38,7 +38,7 @@ class MotorGridFileTest(AsyncIOTestCase):
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.run_until_complete(self._reset())
|
||||
super(MotorGridFileTest, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
@asyncio_test
|
||||
async def test_attributes(self):
|
||||
|
||||
@ -34,13 +34,13 @@ class TestAsyncIOGridFSBucket(AsyncIOTestCase):
|
||||
await self.db.drop_collection("alt.chunks")
|
||||
|
||||
def setUp(self):
|
||||
super(TestAsyncIOGridFSBucket, self).setUp()
|
||||
super().setUp()
|
||||
self.loop.run_until_complete(self._reset())
|
||||
self.bucket = AsyncIOMotorGridFSBucket(self.db)
|
||||
|
||||
def tearDown(self):
|
||||
self.loop.run_until_complete(self._reset())
|
||||
super(TestAsyncIOGridFSBucket, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
@asyncio_test
|
||||
async def test_basic(self):
|
||||
|
||||
@ -51,7 +51,7 @@ class TestReplicaSetClientAgainstStandalone(AsyncIOTestCase):
|
||||
standalone.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestReplicaSetClientAgainstStandalone, self).setUp()
|
||||
super().setUp()
|
||||
if test.env.is_replica_set:
|
||||
raise SkipTest(
|
||||
"Connected to a replica set, not a standalone mongod")
|
||||
|
||||
@ -31,7 +31,7 @@ from test.utils import TestListener, session_ids
|
||||
class TestAsyncIOSession(AsyncIOTestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAsyncIOSession, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
if not env.sessions_enabled:
|
||||
raise SkipTest("Sessions not supported")
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ class MotorTest(testing.AsyncTestCase):
|
||||
ssl = False # If True, connect with SSL, skip if mongod isn't SSL
|
||||
|
||||
def setUp(self):
|
||||
super(MotorTest, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
if self.ssl and not env.mongod_started_with_ssl:
|
||||
raise SkipTest("mongod doesn't support SSL, or is down")
|
||||
@ -118,12 +118,12 @@ class MotorTest(testing.AsyncTestCase):
|
||||
def tearDown(self):
|
||||
env.sync_cx.motor_test.test_collection.delete_many({})
|
||||
self.cx.close()
|
||||
super(MotorTest, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
|
||||
class MotorReplicaSetTestBase(MotorTest):
|
||||
def setUp(self):
|
||||
super(MotorReplicaSetTestBase, self).setUp()
|
||||
super().setUp()
|
||||
if not env.is_replica_set:
|
||||
raise SkipTest("Not connected to a replica set")
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ class MotorAuthTest(MotorTest):
|
||||
@env.require_auth
|
||||
@env.require_version_min(4, 0)
|
||||
def setUp(self):
|
||||
super(MotorAuthTest, self).setUp()
|
||||
super().setUp()
|
||||
self._reset()
|
||||
|
||||
def tearDown(self):
|
||||
|
||||
@ -129,3 +129,26 @@ class MotorTestBasic(MotorTest):
|
||||
# MOTOR-104, TypeError: Can't instantiate abstract class C with abstract
|
||||
# methods collection, db, subcollection.
|
||||
C()
|
||||
|
||||
@gen_test
|
||||
async def test_inheritance(self):
|
||||
class CollectionSubclass(motor.MotorCollection):
|
||||
pass
|
||||
|
||||
class DatabaseSubclass(motor.MotorDatabase):
|
||||
def __getitem__(self, name):
|
||||
return CollectionSubclass(self, name)
|
||||
|
||||
class ClientSubclass(motor.MotorClient):
|
||||
def __getitem__(self, name):
|
||||
return DatabaseSubclass(self, name)
|
||||
|
||||
cx = ClientSubclass(test.env.uri, **self.get_client_kwargs())
|
||||
self.assertIsInstance(cx, ClientSubclass)
|
||||
|
||||
db = cx['testdb']
|
||||
self.assertIsInstance(db, DatabaseSubclass)
|
||||
|
||||
coll = db['testcoll']
|
||||
self.assertIsInstance(coll, CollectionSubclass)
|
||||
self.assertIsNotNone(await coll.insert_one({}))
|
||||
|
||||
@ -31,7 +31,7 @@ class MotorChangeStreamTest(MotorTest):
|
||||
@classmethod
|
||||
@env.require_version_min(3, 6)
|
||||
def setUpClass(cls):
|
||||
super(MotorChangeStreamTest, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
if env.is_standalone:
|
||||
raise SkipTest("Standalone")
|
||||
|
||||
|
||||
@ -140,13 +140,13 @@ class MotorCoreTest(MotorTest):
|
||||
|
||||
class MotorCoreTestGridFS(MotorTest):
|
||||
def setUp(self):
|
||||
super(MotorCoreTestGridFS, self).setUp()
|
||||
super().setUp()
|
||||
self.sync_fs = GridFSBucket(env.sync_cx.test)
|
||||
self.sync_fs.upload_from_stream_with_id(1, 'filename', source=b'')
|
||||
|
||||
def tearDown(self):
|
||||
self.sync_fs.delete(file_id=1)
|
||||
super(MotorCoreTestGridFS, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
def test_gridfs_attrs(self):
|
||||
motor_gridfs_only = set(['collection']).union(motor_only)
|
||||
|
||||
@ -517,12 +517,12 @@ class MotorCursorTest(MotorMockServerTest):
|
||||
|
||||
class MotorCursorMaxTimeMSTest(MotorTest):
|
||||
def setUp(self):
|
||||
super(MotorCursorMaxTimeMSTest, self).setUp()
|
||||
super().setUp()
|
||||
self.io_loop.run_sync(self.maybe_skip)
|
||||
|
||||
def tearDown(self):
|
||||
self.io_loop.run_sync(self.disable_timeout)
|
||||
super(MotorCursorMaxTimeMSTest, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
async def maybe_skip(self):
|
||||
if (await server_is_mongos(self.cx)):
|
||||
|
||||
@ -40,7 +40,7 @@ class MotorGridFileTest(MotorTest):
|
||||
|
||||
def tearDown(self):
|
||||
self.io_loop.run_sync(self._reset)
|
||||
super(MotorGridFileTest, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
@gen_test
|
||||
async def test_attributes(self):
|
||||
|
||||
@ -33,13 +33,13 @@ class MotorGridFSBucketTest(MotorTest):
|
||||
await self.db.drop_collection("alt.chunks")
|
||||
|
||||
def setUp(self):
|
||||
super(MotorGridFSBucketTest, self).setUp()
|
||||
super().setUp()
|
||||
self.io_loop.run_sync(self._reset)
|
||||
self.bucket = motor.MotorGridFSBucket(self.db)
|
||||
|
||||
def tearDown(self):
|
||||
self.io_loop.run_sync(self._reset)
|
||||
super(MotorGridFSBucketTest, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
@gen_test
|
||||
async def test_basic(self):
|
||||
|
||||
@ -62,7 +62,7 @@ class TestReplicaSetClientAgainstStandalone(MotorTest):
|
||||
MotorClient but only if the database at DB_IP and DB_PORT is a standalone.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestReplicaSetClientAgainstStandalone, self).setUp()
|
||||
super().setUp()
|
||||
if test.env.is_replica_set:
|
||||
raise SkipTest(
|
||||
"Connected to a replica set, not a standalone mongod")
|
||||
|
||||
@ -32,7 +32,7 @@ from test.utils import TestListener, session_ids
|
||||
class MotorSessionTest(MotorTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(MotorSessionTest, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
if not env.sessions_enabled:
|
||||
raise SkipTest("Sessions not supported")
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ class MotorSSLTest(MotorTest):
|
||||
if not test.env.server_is_resolvable:
|
||||
raise SkipTest("The hostname 'server' must be a localhost alias")
|
||||
|
||||
super(MotorSSLTest, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def test_config_ssl(self):
|
||||
self.assertRaises(ValueError, motor.MotorClient, ssl='foo')
|
||||
|
||||
@ -35,7 +35,7 @@ from test.test_environment import env, CA_PEM, CLIENT_PEM
|
||||
# the convenience of self.fetch().
|
||||
class GridFSHandlerTestBase(AsyncHTTPTestCase):
|
||||
def setUp(self):
|
||||
super(GridFSHandlerTestBase, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
self.fs = gridfs.GridFS(test.env.sync_cx.motor_test)
|
||||
|
||||
@ -69,7 +69,7 @@ class GridFSHandlerTestBase(AsyncHTTPTestCase):
|
||||
|
||||
def tearDown(self):
|
||||
self.fs.delete(self.file_id)
|
||||
super(GridFSHandlerTestBase, self).tearDown()
|
||||
super().tearDown()
|
||||
|
||||
def get_app(self):
|
||||
return Application([
|
||||
@ -184,7 +184,7 @@ class GridFSHandlerTest(GridFSHandlerTestBase):
|
||||
|
||||
class TZAwareGridFSHandlerTest(GridFSHandlerTestBase):
|
||||
def motor_db(self):
|
||||
return super(TZAwareGridFSHandlerTest, self).motor_db(tz_aware=True)
|
||||
return super().motor_db(tz_aware=True)
|
||||
|
||||
def test_tz_aware(self):
|
||||
now = datetime.datetime.utcnow()
|
||||
|
||||
@ -20,7 +20,7 @@ class Version(tuple):
|
||||
|
||||
def __new__(cls, *version):
|
||||
padded_version = cls._padded(version, 4)
|
||||
return super(Version, cls).__new__(cls, tuple(padded_version))
|
||||
return super().__new__(cls, tuple(padded_version))
|
||||
|
||||
@classmethod
|
||||
def _padded(cls, iter, length, padding=0):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user