pycharm中Asyncconcontextmanager的类型提示
我正在使用Pycharm Professional 2022.1。 我有一种异步方法在异步环境中使用数据库来管理会话
@contextlib.asynccontextmanager
async def begin_transaction(self) -> AsyncIterator[Session]:
_session: Optional[Session] = None
try:
await self.session_lock.acquire()
_session: Session = Session()
yield _session
finally:
if _session is not None:
_session.commit()
_session.close()
if self.session_lock.locked():
self.session_lock.release()
,但是当我在异步语句中使用此方法时,Pycharm无法识别类型:
net/5zozl.png“ rel =“ nofollow noreferrer”>
那么,您是否有任何技巧可以键入提示a的输出变量,而无需手动指定pycharm上的语句?
I'm using Pycharm Professional 2022.1.
I have an async method I use to manage the session with my database in asynchronous environments
@contextlib.asynccontextmanager
async def begin_transaction(self) -> AsyncIterator[Session]:
_session: Optional[Session] = None
try:
await self.session_lock.acquire()
_session: Session = Session()
yield _session
finally:
if _session is not None:
_session.commit()
_session.close()
if self.session_lock.locked():
self.session_lock.release()
But, when I use this method in an async statement, Pycharm doesn't recognize the type :
To use PyCharm auto-completion, I have to manually specify the type of the Session :
So, do you have any trick to type hint the output variable of a with statement on PyCharm without having to manually specify it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论