Skip to content

No Attribute Error for modules #8210

Description

@nameer

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

Activity

  1. JukkaL commented on Jan 9, 2020

    @JukkaL
    Collaborator

    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?

  2. nameer commented on Jan 23, 2020

    @nameer
    Author

    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.

  3. hauntsaninja commented on Aug 7, 2020

    @hauntsaninja
    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?

  4. nameer commented on Aug 8, 2020

    @nameer
    Author

    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)
    
  5. gvanrossum commented on Aug 8, 2020

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

  6. hauntsaninja commented on Aug 8, 2020

    @hauntsaninja
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions