Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move deprecated methods to the end of the class #240

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 56 additions & 55 deletions peewee_async.py
Original file line number Diff line number Diff line change
@@ -273,16 +273,6 @@ def __init__(self, database, **kwargs):
**self.connect_params_async
)

def __setattr__(self, name, value):
if name == 'allow_sync':
warnings.warn(
"`.allow_sync` setter is deprecated, use either the "
"`.allow_sync()` context manager or `.set_allow_sync()` "
"method.", DeprecationWarning)
self._allow_sync = value
else:
super().__setattr__(name, value)

async def aio_connect(self):
"""Set up async connection on default event loop.
"""
@@ -296,55 +286,11 @@ async def aio_close(self):
"""
await self.aio_pool.terminate()

async def connect_async(self):
warnings.warn(
"`connect_async` is deprecated, use `aio_connect` instead.",
DeprecationWarning
)
await self.aio_connect()

async def close_async(self):
warnings.warn(
"`close_async` is deprecated, use `aio_close` instead.",
DeprecationWarning
)
await self.aio_close()

def transaction_async(self):
"""Similar to peewee `Database.transaction()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`atomic_async` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return self.aio_atomic()

def aio_atomic(self):
"""Similar to peewee `Database.transaction()` method, but returns
asynchronous context manager.
"""
return TransactionContextManager(self.aio_pool)

def atomic_async(self):
"""Similar to peewee `Database.atomic()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`atomic_async` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return self.aio_atomic()

def savepoint_async(self, sid=None):
"""Similar to peewee `Database.savepoint()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`savepoint` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return savepoint(self, sid=sid)
return TransactionContextManager(self.aio_pool)

def set_allow_sync(self, value):
"""Allow or forbid sync queries for the database. See also
@@ -416,6 +362,61 @@ async def aio_execute(self, query, fetch_results=None):
fetch_results = fetch_results or getattr(query, 'fetch_results', None)
return await self.aio_execute_sql(sql, params, fetch_results=fetch_results)

#### Deprecated methods ####
def __setattr__(self, name, value):
if name == 'allow_sync':
warnings.warn(
"`.allow_sync` setter is deprecated, use either the "
"`.allow_sync()` context manager or `.set_allow_sync()` "
"method.", DeprecationWarning)
self._allow_sync = value
else:
super().__setattr__(name, value)

def atomic_async(self):
"""Similar to peewee `Database.atomic()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`atomic_async` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return self.aio_atomic()

def savepoint_async(self, sid=None):
"""Similar to peewee `Database.savepoint()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`savepoint` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return savepoint(self, sid=sid)

async def connect_async(self):
warnings.warn(
"`connect_async` is deprecated, use `aio_connect` instead.",
DeprecationWarning
)
await self.aio_connect()

async def close_async(self):
warnings.warn(
"`close_async` is deprecated, use `aio_close` instead.",
DeprecationWarning
)
await self.aio_close()

def transaction_async(self):
"""Similar to peewee `Database.transaction()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`atomic_async` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return self.aio_atomic()


class AioPool(metaclass=abc.ABCMeta):
"""Asynchronous database connection pool.