Skip to content

Commit

Permalink
chore: move deprecated methods to the end of the class
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos committed May 13, 2024
1 parent f7db55e commit 70e3e79
Showing 1 changed file with 56 additions and 55 deletions.
111 changes: 56 additions & 55 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 70e3e79

Please sign in to comment.