Repository navigation
No Attribute Error for modules #8210
Description
Activity
Can you narrow down the failure to a small Python example? After
pip torchtype checking this program usingmypy t.pygenerated no errors:import torch.jit
Torch installs stubs files -- maybe the ones bundled with 1.2.0 are incomplete? Have you tried the latest torch?
Here's a sample code:
import torch print(torch.jit)
And run
mypy t.py.I have tried the same with latest torch, and got the same result.
I also can't repro this, which makes two of us, so closing, although if you post more information, I'll check if I can repro. Do you have any extra mypy config?
Here's a sample code:
import torch print(torch.jit)
And run
mypy t.py.I have tried the same with latest torch, and got the same result.
@hauntsaninja Did you try this? I can confirm that this is still happening in the version
0.782mypy -c 'import torch; print(torch.jit)'raises
<string>:1: error: Module has no attribute "jit" Found 1 error in 1 file (checked 1 source file)Does it still fail if you change the program to
import torch.jit print(torch.jit)?
Without looking at the stubs I don't know if this will make a difference, but it easily could, if the stub for torch doesn't pre-import torch.jit in its
__init__.I couldn't install the torch versions you mentioned... but you'd said it didn't work on latest torch, which is what I can't repro. All in all, seems like an issue with torch for your version, so I don't think there's anything for mypy to do here. If torch releases bug fixes for old versions I'd recommend filing an issue on their tracker, otherwise your best option is probably to upgrade.
(del2) ~/tmp/del2 λ pip list Package Version ----------------- ------- future 0.18.2 mypy 0.782 mypy-extensions 0.4.3 numpy 1.19.1 Pillow 7.2.0 pip 20.2.1 setuptools 49.2.1 torch 1.6.0 torchvision 0.7.0 typed-ast 1.4.1 typing-extensions 3.7.4.2 wheel 0.34.2 (del2) ~/tmp/del2 λ mypy -c 'import torch; print(torch.jit)' Success: no issues found in 1 source file (del2) ~/tmp/del2 λ mypy -c 'import torch; reveal_type(torch.jit.script)' <string>:1: note: Revealed type is 'def (obj: Any, optimize: Any =, _frames_up: Any =, _rcb: Any =) -> Any'
To help you understand the issue:
pip install mypy). Also, I have torch installed (pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html). In code, I'm using the moduletorch.jit.Module has no attribute "jit"mypy -p projPlease feel free to edit the issue