django-stubs
django-stubs copied to clipboard
AttributeError: 'NoneType' object has no attribute '__module__'. Did you mean: '__reduce__'?
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:
I'm seeing this also. There's a similar report in https://github.com/typeddjango/django-stubs/issues/196 which was fixed in https://github.com/typeddjango/django-stubs/pull/199. However, I suspect https://github.com/typeddjango/django-stubs/pull/1495 may have regressed this.
Looking through https://github.com/typeddjango/django-stubs/pull/1495
-
This refactors
get_field_related_model_cls
to raise an exception instead of returningNone
. However, the function still appears to be returningNone
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 gettingNone
returned rather than an exception. - I've verified on my local that restoring the
None
check mentioned above fixes the crash and letsmypy
continue for my project.
@SingingTree I confirmed, it works for me as well.