typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.6k stars 449 forks source link

NameError: value for final name "attr_class_makers" was not set #1933

Open amiwrpremium opened 9 months ago

amiwrpremium commented 9 months ago

Bug report

What's wrong

NameError: value for final name "attr_class_makers" was not set

I run mypy on my project using: mypy --config-file ../.mypy.ini --namespace-packages -p samirpy --show-traceback I got the following error

/Users/amiwr/PycharmProjects/samir/venv/lib/python3.11/site-packages/mypy/typeshed/stdlib/typing.pyi:141: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.7.1
Traceback (most recent call last):
  File "mypy/semanal.py", line 6525, in accept
  File "mypy/nodes.py", line 1140, in accept
  File "mypy/semanal.py", line 1608, in visit_class_def
  File "mypy/semanal.py", line 1693, in analyze_class
  File "mypy/semanal.py", line 1727, in analyze_class_body_common
  File "mypy/semanal.py", line 1793, in apply_class_plugin_hooks
  File "mypy/plugin.py", line 873, in get_class_decorator_hook
  File "mypy/plugin.py", line 898, in _find_hook
  File "mypy/plugin.py", line 873, in <lambda>
  File "mypy/plugins/default.py", line 144, in get_class_decorator_hook
NameError: value for final name "attr_class_makers" was not set
/Users/amiwr/PycharmProjects/samir/venv/lib/python3.11/site-packages/mypy/typeshed/stdlib/typing.pyi:141: : note: use --pdb to drop into pdb

I believe get_class_decorator_hook method in NewSemanalDjangoPlugin class needs to return something. Since such class is not implemented, its returning Plugin class get_class_decorator_hook which is essentially just a return None

How is that should be

It should continue to work as usual.

System information

MyPy Config

;mypy configurations:
[mypy]
python_version = 3.11
ignore_missing_imports = True
warn_unused_configs = True
warn_redundant_casts = True
disallow_untyped_defs = True
no_implicit_optional = True
check_untyped_defs = True
mypy_path = ./src/samirpy/
plugins =
    mypy_django_plugin.main

[mypy-*.migrations.*]
ignore_errors = True

[pydantic-mypy]
init_forbid_extra = True

[mypy.plugins.django-stubs]
django_settings_module = "samirpy.samir.settings"
amiwrpremium commented 9 months ago

Upon my further investigation I realized its some sort of conflict with the dependency injector framework. More specifically I think it happens when I'm using the @inject decorator. I think it's an issue with django-stub mypy plugin because if I remove mypy_django_plugin.main in mypy.ini plugin configuration, mypy continues to work just fine.