Type annotations with .pyi file in PyCharm doesn't work for dynamic attributes

跟風遠走 提交于 2020-04-30 11:24:42

问题


My goal is to have autocomplete in the Pycharm Editor (in Python Console it works fine) for arguments used by pytransition module. (Some background info about the module here)

The idea is to use the recipe mentioned on PyCharm forum in regard to dynamic code: related pyi stub file with type annotations for the class.

That works well if I define the attribute like this:

# class.pyi
class Model(object):
    evaporate = None

# class.py

But that doesn't work if I try to define the attributes dynamically, in the manner described here:

# class.pyi
class Model(object):
    for x in ['ionize', 'melt']:
        locals()[x] = None

What could be the reason and how to overcome that?

来源:https://stackoverflow.com/questions/60209508/type-annotations-with-pyi-file-in-pycharm-doesnt-work-for-dynamic-attributes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!