Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minor Bug] Pylint E1101 Module 'torch' has no 'from_numpy' member #701

Closed
willfrey opened this issue Feb 8, 2017 · 20 comments
Closed

[Minor Bug] Pylint E1101 Module 'torch' has no 'from_numpy' member #701

willfrey opened this issue Feb 8, 2017 · 20 comments
Labels
todo Not as important as medium or high priority tasks, but we will work on these.

Comments

@willfrey
Copy link
Contributor

willfrey commented Feb 8, 2017

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
@soumith
Copy link
Member

soumith commented Feb 9, 2017

the workaround seems pretty ugly. is there no way to tell pylint to filter certain errors?

@apaszke apaszke added enhancement todo Not as important as medium or high priority tasks, but we will work on these. labels Feb 17, 2017
@naifrec
Copy link
Contributor

naifrec commented Feb 20, 2017

I may add that pylint (1.6.5) does not pick up cat, topk and masked_select as member functions either.

@soumith soumith added this to Low Priority in Issue Status Aug 23, 2017
@soumith
Copy link
Member

soumith commented Sep 13, 2017

i dont think we'll be fixing this. (i dont know if there's a way to do it either).

@soumith soumith closed this as completed Sep 13, 2017
@gauss256
Copy link

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

@kindlychung
Copy link

mypy seems to be able to pick up these members.

@neverfox
Copy link

neverfox commented Apr 2, 2018

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.*

bddppq pushed a commit to bddppq/pytorch that referenced this issue Apr 17, 2018
…9c90c8

Previous import was a4dcc47791eb127652f5aaddd51d8896d446a067

Included changes:
- **[985af3f](onnx/onnx@985af3f)**: Update PythonAPIOverview.md (pytorch#738) <Dmytro Dzhulgakov>
- **[b69be33](onnx/onnx@b69be33)**: Add backend test for upsample (pytorch#729) <Sebastian Meßmer>
- **[0d9496e](onnx/onnx@0d9496e)**: Input test data of concat op should be float (pytorch#711) <Changming Sun>
- **[20bcb8b](onnx/onnx@20bcb8b)**: Fix the spec for batchnorm and instancenorm (pytorch#733) <Lu Fang>
- **[c9f825f](onnx/onnx@c9f825f)**: Refine a little bit about op spec. (pytorch#666) <Ke Zhang>
- **[a484eb2](onnx/onnx@a484eb2)**: Fix an error in Conv doc (pytorch#731) <Lu Fang>
- **[7410cc4](onnx/onnx@7410cc4)**: Fix incorrect package output paths (pytorch#730) <bddppq>
- **[be546e2](onnx/onnx@be546e2)**: Improve optimizer's API and docs (pytorch#713) <Lu Fang>
- **[c61506f](onnx/onnx@c61506f)**: Fix the shape inference python API (pytorch#716) <Lu Fang>
- **[e9d4134](onnx/onnx@e9d4134)**: Fix cmake on windows when not building python extension (pytorch#728) <bddppq>
- **[72187aa](onnx/onnx@72187aa)**: Add value_info support in make_graph (pytorch#726) <Lu Fang>
- **[67b7d89](onnx/onnx@67b7d89)**: Fix gen_proto in cmake (pytorch#719) <bddppq>
- **[fcb4ae3](onnx/onnx@fcb4ae3)**: docs rewording: Important Python Functions -> Python API Overview (pytorch#721) <anderspapitto>
- **[24275d6](onnx/onnx@24275d6)**: Ignore .eggs directory when doing lint (pytorch#722) <bddppq>
- **[54be8fa](onnx/onnx@54be8fa)**: Use cmake3 if it's available (pytorch#718) <bddppq>
- **[b8c4238](onnx/onnx@b8c4238)**: Add python function docs (pytorch#714) <Lu Fang>
- **[e177493](onnx/onnx@e177493)**: Remove unused cmake utils (pytorch#712) <bddppq>
- **[72d6ad6](onnx/onnx@72d6ad6)**: Remove pycmd from CMake (pytorch#710) <bddppq>
- **[93f0d40](onnx/onnx@93f0d40)**: Fix windows local build (pytorch#709) <Raymond Yang>
- **[6734224](onnx/onnx@6734224)**: CMake fixes and setup.py cleanup (pytorch#706) <bddppq>
- **[7f6a4fd](onnx/onnx@7f6a4fd)**: Add docs to explain important functions in ONNX Infra (pytorch#682) <Lu Fang>
- **[f0f6b3d](onnx/onnx@f0f6b3d)**: fix hardmax test cases make output dtype same as input (pytorch#705) <Wenhao Hu>
- **[c970f0c](onnx/onnx@c970f0c)**: Fix the Dummy backend (pytorch#701) <Lu Fang>
- **[2af45df](onnx/onnx@2af45df)**: setup.py uses cmake build system (pytorch#606) <anderspapitto>
- **[dfcaade](onnx/onnx@dfcaade)**: clean up unused variable left by removing consumed_input (pytorch#697) <bddppq>
- **[accfc74](onnx/onnx@accfc74)**: Remove incorrect backend test (pytorch#700) <Lu Fang>
- **[e558732](onnx/onnx@e558732)**: add max inclusive version to defs.get_schema function (pytorch#695) <Wenhao Hu>
- **[16f02eb](onnx/onnx@16f02eb)**: add API to add domain to min/max version for extension. (pytorch#694) <Ke Zhang>
- **[3e560dd](onnx/onnx@3e560dd)**: Fix doc for initializer (pytorch#690) <bddppq>
- **[6cc4f53](onnx/onnx@6cc4f53)**: Add model save function (pytorch#692) <Lu Fang>
- **[21eaf9b](onnx/onnx@21eaf9b)**: Changing the string discussing versions in operator specifications. (pytorch#691) <Niklas Gustafsson>
- **[3b0cdf4](onnx/onnx@3b0cdf4)**: Minor code quality improvements in optimizer/ (pytorch#612) <Sebastian Meßmer>
- **[641f126](onnx/onnx@641f126)**: Fix Gemm doc wording (pytorch#689) <bddppq>
- **[4a0ec75](onnx/onnx@4a0ec75)**: Clarifies installation error message when external protobuf dependencies are missing (pytorch#684) <Daniel J. H>
- **[960a2c3](onnx/onnx@960a2c3)**: Check outputs dtype in backend tests (pytorch#567) <bddppq>
- **[1d7dee4](onnx/onnx@1d7dee4)**: Fix Average pool test cases converted from PyTorch (pytorch#677) <Lu Fang>
- **[36d7fff](onnx/onnx@36d7fff)**: Fix Attribute default value pybind11 binding (pytorch#671) <bddppq>
- **[0536866](onnx/onnx@0536866)**: git ignore .pytest_cache (pytorch#674) <bddppq>
- **[afc84ac](onnx/onnx@afc84ac)**: Update README.md (pytorch#672) <Dmytro Dzhulgakov>
- **[9d2b530](onnx/onnx@9d2b530)**: Revert "[Typing 1/3] Setup mypy type checker (pytorch#607)" (pytorch#667) <bddppq>
- **[086727e](onnx/onnx@086727e)**: [Typing 1/3] Setup mypy type checker (pytorch#607) <Sebastian Meßmer>
- **[5716e20](onnx/onnx@5716e20)**: Convert all Node tests to Model tests (pytorch#651) <bddppq>
- **[6fe932a](onnx/onnx@6fe932a)**: Replace unittest.skip with custom exception (pytorch#659) <Dmytro Dzhulgakov>
- **[ecac1c1](onnx/onnx@ecac1c1)**: Merge Rel 1.1.0 branch into master (pytorch#657) <Anirudh>
- **[5cb999d](onnx/onnx@5cb999d)**: Minor cleanups to shape inference (pytorch#653) <anderspapitto>
- **[f4acf28](onnx/onnx@f4acf28)**: Remove allowconsumed enforceconsumed from op schema. (pytorch#617) <Ke Zhang>
- **[a8e4648](onnx/onnx@a8e4648)**: Adjust link flags when built in Windows Debug mode (pytorch#647) <Yinghai Lu>
- **[7c009fe](onnx/onnx@7c009fe)**: Fix lint error in optimizer test (pytorch#656) <bddppq>
- **[063d12f](onnx/onnx@063d12f)**: Fix optimizer split pass for models with constant output (pytorch#652) <bddppq>
@dscarmo
Copy link

dscarmo commented Nov 13, 2018

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

@moi90
Copy link
Contributor

moi90 commented Jan 16, 2019

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, ...?

@cardoso-neto
Copy link

cardoso-neto commented Apr 21, 2019

Maybe one could change from torch._C import * to from 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?

Zoufalc added a commit to Zoufalc/qiskit-aqua that referenced this issue Aug 9, 2019
torch has no memer function from_numpy because it is actually _C.from_numpy. This induces an error when running lint.
See pytorch/pytorch#701
@Immocat
Copy link

Immocat commented Sep 28, 2019

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

@miranthajayatilake
Copy link

On VS code:
Adding "python.linting.enabled": false also worked in this case.

muffgaga pushed a commit to electronicvisions/code-format that referenced this issue Jan 22, 2020
Fix for pytorch/pytorch#701

Change-Id: I3a652c7de7b4756fa0421c14282928994155ca28
@SelvamArul
Copy link

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.

@zzj0402
Copy link

zzj0402 commented May 25, 2020

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.

adbugger added a commit to adbugger/FewShot that referenced this issue May 30, 2020
The VSCode python linter does not find dynamically generated members for
torch, such as torch.empty and torch.rand. Adding an entry in the
.pylintrc file silences those warnings.
See pytorch/pytorch#701 for discussion.
@xasopheno
Copy link

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.

@yangfansun
Copy link

maybe "python.linting.pylintArgs": ["--generate-members"] will solve the problem.
https://stackoverflow.com/questions/56844378/pylint-no-member-issue-but-code-still-works-vscode

manoelmarques pushed a commit to qiskit-community/qiskit-machine-learning that referenced this issue Feb 27, 2021
torch has no memer function from_numpy because it is actually _C.from_numpy. This induces an error when running lint.
See pytorch/pytorch#701
KyleCZH pushed a commit to KyleCZH/pytorch that referenced this issue Sep 20, 2021
KyleCZH pushed a commit to KyleCZH/pytorch that referenced this issue Sep 20, 2021
@maejav
Copy link

maejav commented Nov 18, 2021

i got this error for torch.randn!!
what sould i do ? i can not fix it with these solutions.

@nguyenvulong
Copy link

You don't have to disable pylint, just add 1 line to the settings.json.
See nguyenvulong/QA#63 for more references.

@vindolineKis
Copy link

I met this problem :
“Module 'torch' has no 'matmul' member “ [{
"resource": "/home/guoguo/project1/quantum_transformer/qtransformer/qtransformer.py",
"owner": "generated_diagnostic_collection_name#0",
"code": {
"value": "E1101:no-member",
"target": {
"$mid": 1,
"path": "/en/latest/user_guide/messages/error/no-member.html",
"scheme": "https",
"authority": "pylint.readthedocs.io"
}
},
"severity": 8,
"message": "Module 'torch' has no 'matmul' member",
"source": "Pylint",
"startLineNumber": 57,
"startColumn": 18,
"endLineNumber": 57,
"endColumn": 30
}], I have followed the above ways to add "python. linting.pylintArgs": ["--generate-members"], but it didn't solve my problem

@BraveDrXuTF
Copy link

"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
]
bro, now it seems not work. I got the problem one morning when typing code with vs code recently.

@liye-yang
Copy link

"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
]
bro, now it seems not work. I got the problem one morning when typing code with vs code recently.

this way seems work:
"pylint.args": [ "--generated-members=numpy.*, torch.*, cv2.*, cv.*" ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo Not as important as medium or high priority tasks, but we will work on these.
Projects
Issue Status
Low Priority
Development

No branches or pull requests