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

AttributeError: 'NoneType' object has no attribute '__module__'. Did you mean: '__reduce__'? #1953

Closed
random1st opened this issue Feb 16, 2024 · 2 comments · Fixed by #1956
Closed
Labels
bug Something isn't working

Comments

@random1st
Copy link

Bug report

What's wrong

mypy . --strict --explicit-package-bases

  File "/Users/xx/Library/Caches/pypoetry/virtualenvs/xxx-CJszIqT8-py3.11/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/Users/xx/Library/Caches/pypoetry/virtualenvs/xxx-CJszIqT8-py3.11/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 100, in main
  File "mypy/main.py", line 182, in run_build
  File "mypy/build.py", line 191, in build
  File "mypy/build.py", line 265, in _build
  File "mypy/build.py", line 2890, in dispatch
  File "mypy/build.py", line 3076, in load_graph
  File "mypy/build.py", line 1998, in __init__
  File "mypy/build.py", line 2292, in compute_dependencies
  File "mypy/plugin.py", line 844, in get_additional_deps
  File "/Users/xx/Library/Caches/pypoetry/virtualenvs/xxx-CJszIqT8-py3.11/lib/python3.11/site-packages/mypy_django_plugin/main.py", line 141, in get_additional_deps
    related_model_module = related_model_cls.__module__
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__module__'. Did you mean: '__reduce__'?

How is that should be

No errors

System information

  • OS:
  • python 3.11:
  • django 5.0.2:
  • mypy 1.8.0:
  • django-stubs 4.2.7:
  • django-stubs-ext 4.2.7:
@random1st random1st added the bug Something isn't working label Feb 16, 2024
@SingingTree
Copy link
Contributor

I'm seeing this also. There's a similar report in #196 which was fixed in #199. However, I suspect #1495 may have regressed this.

Looking through #1495

  • This refactors get_field_related_model_cls to raise an exception instead of returning None. However, the function still appears to be returning None in some cases.
  • These lines remove the None check in favour of catching the new exception. However, the following line is now failing for me and OP as we're getting None returned rather than an exception.
  • I've verified on my local that restoring the None check mentioned above fixes the crash and lets mypy continue for my project.

@random1st
Copy link
Author

@SingingTree I confirmed, it works for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants