Skip to content

Commit

Permalink
Added missing slots to context managers (#763)
Browse files Browse the repository at this point in the history
* Add missing slot to context managers

* Bump version and fix CHANGES
  • Loading branch information
Pliner committed Dec 9, 2020
1 parent 78543a1 commit f8c320e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,9 @@
1.1.0b2 (2020-12-09)
^^^^^^^^^^^^^^^^^^^^

* Added missing slots to context managers `#763 <https://github.com/aio-libs/aiopg/pull/763>`_


1.1.0b1 (2020-12-07)
^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion aiopg/__init__.py
Expand Up @@ -21,7 +21,7 @@
'Connection', 'Cursor', 'Pool', 'version', 'version_info',
'DEFAULT_TIMEOUT', 'IsolationLevel', 'Transaction')

__version__ = '1.1.0b1'
__version__ = '1.1.0b2'

version = __version__ + ' , Python ' + sys.version

Expand Down
12 changes: 11 additions & 1 deletion aiopg/utils.py
Expand Up @@ -100,6 +100,8 @@ async def __aexit__(self, exc_type, exc, tb):


class _SAConnectionContextManager(_ContextManager):
__slots__ = ()

def __aiter__(self):
return self

Expand All @@ -108,21 +110,25 @@ async def __anext__(self):
self._obj = await self._coro

try:
return (await self._obj.__anext__())
return await self._obj.__anext__()
except StopAsyncIteration:
self._obj.close()
self._obj = None
raise


class _PoolContextManager(_ContextManager):
__slots__ = ()

async def __aexit__(self, exc_type, exc, tb):
self._obj.close()
await self._obj.wait_closed()
self._obj = None


class _TransactionPointContextManager(_ContextManager):
__slots__ = ()

async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback_savepoint()
Expand All @@ -133,6 +139,8 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):


class _TransactionBeginContextManager(_ContextManager):
__slots__ = ()

async def __aexit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
await self._obj.rollback()
Expand All @@ -143,6 +151,8 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):


class _TransactionContextManager(_ContextManager):
__slots__ = ()

async def __aexit__(self, exc_type, exc, tb):
if exc_type:
await self._obj.rollback()
Expand Down

0 comments on commit f8c320e

Please sign in to comment.