Pylint with pytorch: Is there a way to tell pylint to look for module in different place?

痴心易碎 提交于 2019-12-11 04:54:09

问题


I am using pytorch and pylint does not recognize few functions for ex: torch.stack however, if I do import torch._C as torch it seems to work fine.

If I do above, actual modules that exist inside torch package like torch.cuda or torch.nn need to imported individually as simply doing torch.cuda would point to torch._C.cuda and hence won't work.

Is there a way to tell pylint to look at both torch and torch._C when I do import torch or even whenever it sees torch? I don't think I would use torch to reference any other thing in my code.


回答1:


A solution for now is to add torch to generated-members:

pylint --generated-members="torch.*" ...

or in pylintrc under the [TYPECHECK] section:

generated-members=torch.*

I found this solution in a reply to the github discussion of the pytorch issue [Minor Bug] Pylint E1101 Module 'torch' has no 'from_numpy' member #701. Less satisfying than whitelisting, because I guess it won't catch if you reference something that actually isn't a member, but it's the best solution I've come across so far.



来源:https://stackoverflow.com/questions/54030714/pylint-with-pytorch-is-there-a-way-to-tell-pylint-to-look-for-module-in-differe

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