Inspection support for modules with dynamically added attributes

Answered

Hi,

I'm using the zmq library, and I get a lot of inspection errors like "Cannot find reference PUB in __init__.py" coming from using zmq.PUB. It turns out it is defined dynamically. I'm coming from eclipse+pydev, and there I just added the "zmq" module to the list of "forced builtins", and the analyzer imported the module and inspected its members, instead of analyzing it statically.

Is it possible to do the same with pycharm?

Thanks,

Noam

2 comments
Comment actions Permalink

Hi Noam,

No, at the moment we import and introspect at runtime only binary modules such as those listed in sys.builtin_module_names and others that we're able to find in sys.path (we then generate so called "binary skeletons" for them). Besides, the recommended way to support such dynamically initialized modules is to use dedicated .pyi stubs for them. As a workaround, you can still include zmq.PUB in the whitelist of "Unresolved references" inspection by invoking the quickfix "Ignore unresolved reference ..." on the corresponding warning.

However, on the whole, this suggestion sounds interesting and promising. I personally didn't know that Pydev allows to analyze arbitrary modules like that. Could you please create a brief feature request about it in our tracker? 

1

Please sign in to leave a comment.