相关疑难解决方法(0)

Python 3.5类型提示动态生成的实例属性

我想为动态生成的对象属性添加Python 3.5类型提示,以便IDE正确地自动完成它们.这里的"动态"是指在类创建期间或在__init__任何其他方法中不存在该属性.

例如,有没有办法通过评论或其他技巧添加这些?如果不是,我可以回退添加虚拟类属性.

例::

 class Request:
      """Example HTTP request object.

      We have `get_user()`  but we do not declare it anyhere.
      """

 ...


 # Pyramid's way of plugging in methods and properties to request, enabled addon capabilities for the framework
 # adds Request.user - done in different part of application lifecycle, not during class creation
 config.add_request_method(auth.get_user, 'user', reify=True)
Run Code Online (Sandbox Code Playgroud)

目标是使这项工作能够使PyCharm和其他IDE完成此属性.

python pycharm python-3.5

9
推荐指数
1
解决办法
1453
查看次数

标签 统计

pycharm ×1

python ×1

python-3.5 ×1