Very minor but worth mentioning.
Pylint isn't picking up that torch has the member function from_numpy. It's because torch.from_numpy is actually torch._C.from_numpy as far as Pylint is concerned.
According to this stackoverflow thread numpy also suffers from this problem.
For reference, you can have Pylint ignore these by wrapping "problematic" calls with the following comments.
# pylint: disable=E1101
tensor = torch.from_numpy(np_array)
# pylint: enable=E1101
the workaround seems pretty ugly. is there no way to tell pylint to filter certain errors?
I may add that pylint (1.6.5) does not pick up cat, topk and masked_select as member functions either.
i dont think we'll be fixing this. (i dont know if there's a way to do it either).
You can suppress all such messages for these modules by editing the appropriate lines of .pylintrc to be like this:
[MASTER]
extension-pkg-whitelist=numpy,torch
[TYPECHECK]
ignored-modules=numpy,torch
ignored-classes=numpy,torch
mypy seems to be able to pick up these members.
Instead of ignoring, you can now do:
[TYPECHECK]
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=numpy.*,torch.*
generated-members=numpy.,torch.
For those using vscode, add to user settings
"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
]
errors-only is not realted to the issue but is useful to supres pep 8/formatting "errors" if you want to
It would be nice to allow the inspection of the module, also for auto-completion. Maybe one could change from torch._C import * to from torch._C import from_numpy, ...?
Maybe one could change
from torch._C import *tofrom torch._C import from_numpy, ...?
This seems simple enough. Are we certain this is the way to go?
I thought we'd need type hints (which would be way harder to convince people to use).
Should we open another issue to discuss @moi90's solution?
generated-members=numpy._,torch._
For those using vscode, add to user settings
"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
]errors-only is not realted to the issue but is useful to supres pep 8/formatting "errors" if you want to
You saved part of my life! hahahaha
On VS code:
Adding "python.linting.enabled": false also worked in this case.
Disabling linting all together (as suggested by @miranthajayatilake ) is not a good solution. Seems pylinthas issues with pytorch but for me flake8 works well.
In VS Code, one can select flake8 by Ctrl + Shift + P ->Select linter -> flake8.
i dont think we'll be fixing this. (i dont know if there's a way to do it either).
Closing issues by "I don't know how to hence not going to" is very naughty.
generated-members=numpy._,torch._
For those using vscode, add to user settings
"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
]errors-only is not realted to the issue but is useful to supres pep 8/formatting "errors" if you want to
If you're using Coc, you can use put the same rule in your coc-settings.json.
Most helpful comment
For those using vscode, add to user settings
"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
]
errors-only is not realted to the issue but is useful to supres pep 8/formatting "errors" if you want to