第三方库中类的属性的覆盖类型提示
我有一个第三方Web-Framework,其某些代码中具有类型的提示。我无法控制上述框架的代码,
假设我有以下内容
from framework import web
...
class UserPosts(web.WebView):
async def get(self):
user_id = await self.request.user_dict['id']
...
web.webview
class在其代码中具有类型提示,request> request
属性被标记为特定的实例在定义中没有user_dict
attr的类,因为这是我的自定义中间件动态附加到请求实例上的。
我想为user_dict
提供类型提示,但我不明白如何处理。
有人可以帮助我提供有关正确方向的提示吗?
谢谢。
I have a 3rd-party web-framework which has type hints in some of its code. I can not control the code of the said framework
Suppose I have following piece
from framework import web
...
class UserPosts(web.WebView):
async def get(self):
user_id = await self.request.user_dict['id']
...
web.WebView
class has type hints in its code and request
attribute is marked as an instance of a specific class which doesn't have user_dict
attr in definition because it is a dict that my custom made middleware dynamically attaches to the request instance.
I want to provide type hint for user_dict
but I don't understand how this can be approached.
Can someone help me with a tip about the right direction?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义一个新课程,
并在该类中覆盖CTOR:
到目前为止,什么都没有改变。
现在调整构造函数,以便使用适当的类型提示,
添加记录和参数验证以品尝,
世界是你的牡蛎!
Define a new class,
and override the ctor within that class:
So far nothing has changed.
Now adjust the constructor so it uses proper type hints,
add logging and parameter validation to taste,
the world is your oyster!