-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support copying and cloning to temporary directories
- Loading branch information
Showing
8 changed files
with
154 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from types import TracebackType | ||
from typing import Any, AsyncContextManager, Callable, Optional, Type | ||
|
||
|
||
class _AwaitableAsyncContextManager: | ||
def __init__(self, cm: "AsyncContextManager[Any]"): | ||
self._cm = cm | ||
|
||
def __await__(self) -> Any: | ||
return self._cm.__aenter__().__await__() | ||
|
||
async def __aenter__(self) -> Any: | ||
return await self._cm.__aenter__() | ||
|
||
async def __aexit__( | ||
self, | ||
exc_type: Optional[Type[BaseException]], | ||
exc_val: Optional[BaseException], | ||
exc_tb: Optional[TracebackType], | ||
) -> Any: | ||
return await self._cm.__aexit__(exc_type, exc_val, exc_tb) | ||
|
||
|
||
def awaitableasynccontextmanager( | ||
cm: Callable[..., "AsyncContextManager[Any]"], | ||
) -> Callable[..., _AwaitableAsyncContextManager]: | ||
return lambda *args, **kwargs: _AwaitableAsyncContextManager(cm(*args, **kwargs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters