我想为动态生成的对象属性添加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)
目标是使这项工作能够使PyCharm和其他IDE完成此属性.