Skip to content

Commit 0d41f0b

Browse files
committed
Support APIClient when use async with context V1.12.4
1 parent 32b31f3 commit 0d41f0b

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

tikhub/client/client.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -129,38 +129,35 @@ def __init__(self,
129129
# Hybrid Parsing
130130
self.HybridParsing = HybridParsing(self.client)
131131

132-
133-
"""
134-
[中文]
135-
136-
这些代码用于实现异步上下文管理器,使得类的实例可以与 async with 语句一起使用,从而在进入和退出时自动处理资源的初始化和清理。
137-
138-
例如:
139-
async with Client(api_key=api_key) as client:
140-
pass
132+
"""
133+
[中文]
141134
142-
这样在退出时会自动调用 __aexit__ 方法,关闭 client。
143-
144-
[English]
145-
146-
This code is used to implement an asynchronous context manager,
147-
which allows instances of a class to be used with the async with statement,
148-
automatically handling the initialization and cleanup of resources when entering and exiting.
149-
150-
For example:
151-
async with Client(api_key=api_key) as client:
152-
pass
135+
这些代码用于实现异步上下文管理器,使得类的实例可以与 async with 语句一起使用,从而在进入和退出时自动处理资源的初始化和清理。
153136
154-
This way, the __aexit__ method is automatically called when exiting, closing the client.
155-
"""
156-
157-
158-
async def __aenter__(self):
159-
return self
160-
161-
162-
async def __aexit__(self, exc_type, exc_val, exc_tb):
163-
await self.client.close()
137+
例如:
138+
async with Client(api_key=api_key) as client:
139+
pass
140+
141+
这样在退出时会自动调用 __aexit__ 方法,关闭 client。
142+
143+
[English]
144+
145+
This code is used to implement an asynchronous context manager,
146+
which allows instances of a class to be used with the async with statement,
147+
automatically handling the initialization and cleanup of resources when entering and exiting.
148+
149+
For example:
150+
async with Client(api_key=api_key) as client:
151+
pass
152+
153+
This way, the __aexit__ method is automatically called when exiting, closing the client.
154+
"""
155+
156+
async def __aenter__(self):
157+
return self
158+
159+
async def __aexit__(self, exc_type, exc_val, exc_tb):
160+
await self.client.close()
164161

165162

166163
if __name__ == '__main__':

tikhub/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# tikhub/version.py
2-
version = "1.12.3"
2+
version = "1.12.4"

0 commit comments

Comments
 (0)