问题
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