Skip to content

No Attribute Error for modules #8210

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

Closed
nameer opened this issue Dec 27, 2019 · 6 comments
Closed

No Attribute Error for modules #8210

nameer opened this issue Dec 27, 2019 · 6 comments

Comments

@nameer
Copy link

nameer commented Dec 27, 2019

To help you understand the issue:

  • I'm Reporting a bug
  • So far I have mypy installed using PyPI (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 module torch.jit.
  • What is the actual behavior/output? Module has no attribute "jit"
  • What is the behavior/output you expect? No error
  • What are the versions of mypy and Python you are using? I tried mypy 0.760, 0.761 as well as 0.720 (I was using this earlier, which had no error). Python version is 3.6.9.
  • I'm using no extra flags, just mypy -p proj

Please feel free to edit the issue

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 9, 2020

Can you narrow down the failure to a small Python example? After pip torch type checking this program using mypy t.py generated 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?

@nameer
Copy link
Author

nameer commented Jan 23, 2020

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
Copy link
Collaborator

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?

@nameer
Copy link
Author

nameer commented Aug 8, 2020

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

mypy -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)

@gvanrossum
Copy link
Member

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

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 8, 2020

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants