Skip to content

Commit

Permalink
Support APIClient when use async with context V1.12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil0ctal committed Aug 9, 2024
1 parent 9e1aa5a commit c2c9b47
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
Binary file added dist/tikhub-1.12.3-py3-none-any.whl
Binary file not shown.
Binary file added dist/tikhub-1.12.3.tar.gz
Binary file not shown.
60 changes: 32 additions & 28 deletions tikhub/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,38 @@ def __init__(self,
# Hybrid Parsing
self.HybridParsing = HybridParsing(self.client)

"""
[中文]
这些代码用于实现异步上下文管理器,使得类的实例可以与 async with 语句一起使用,从而在进入和退出时自动处理资源的初始化和清理。
例如:
async with Client(api_key=api_key) as client:
pass
这样在退出时会自动调用 __aexit__ 方法,关闭 client。
[English]
This code is used to implement an asynchronous context manager,
which allows instances of a class to be used with the async with statement,
automatically handling the initialization and cleanup of resources when entering and exiting.
For example:
async with Client(api_key=api_key) as client:
pass
This way, the __aexit__ method is automatically called when exiting, closing the client.
"""
async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.client.close()

"""
[中文]
这些代码用于实现异步上下文管理器,使得类的实例可以与 async with 语句一起使用,从而在进入和退出时自动处理资源的初始化和清理。
例如:
async with Client(api_key=api_key) as client:
pass
这样在退出时会自动调用 __aexit__ 方法,关闭 client。
[English]
This code is used to implement an asynchronous context manager,
which allows instances of a class to be used with the async with statement,
automatically handling the initialization and cleanup of resources when entering and exiting.
For example:
async with Client(api_key=api_key) as client:
pass
This way, the __aexit__ method is automatically called when exiting, closing the client.
"""


async def __aenter__(self):
return self


async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.client.close()


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tikhub/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# tikhub/version.py
version = "1.12.2"
version = "1.12.3"

0 comments on commit c2c9b47

Please sign in to comment.