1

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.

Umang Gupta
  • 15,022
  • 6
  • 48
  • 66
  • 1
    I'm looking for a similar solution. I tried adding `--extension-pkg-whitelist=torch` to my `pylintrc` file, as an adaptation of the solution from , but I'm still getting the `E1101: Module 'torch' has no 'stack' member (no-member)` errors. – Jonathan A. Gross May 20 '19 at 17:49
  • Yes I tried that too, it doesnot work. – Umang Gupta May 20 '19 at 18:19

1 Answers1

2

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.