django-stubs
django-stubs copied to clipboard
Model class definition error: Explicit "Any" is not allowed
When I create model.py with the following content:
# -*- coding: utf-8 -*-
from django.contrib.auth import get_user_model
from django.db import models
User = get_user_model()
class BlogPost(models.Model):
"""Example model with different fields and a foreign key."""
author = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.TextField()
is_published = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self) -> str:
"""Custom representation."""
reveal_type(self.id)
return '<BlogPost {0}>'.format(self.id)
And following setting:
[mypy]
disallow_any_explicit = True
plugins =
mypy_django_plugin.main
[mypy.plugins.django-stubs]
django_settings_module = server.settings
That's what I get:
» PYTHONPATH=${PYTHONPATH}:${PWD} mypy server
server/apps/main/models.py:9: error: Explicit "Any" is not allowed
server/apps/main/models.py:21: note: Revealed type is 'builtins.int*'
Reproduction link: https://github.com/sobolevn/django_stubs_example (note, that you have to uncomment disallow_any_explicit = True in setup.cfg)
Versions: django2.2, python3.7, django-stubs1.1
I am not sure why server/apps/main/models.py:9: error: Explicit "Any" is not allowed is raised. And I guess, that it should not be. Since there's not explicit Any.
This might be related to https://github.com/typeddjango/django-stubs/issues/64
Same issue here, reporting Explicite "Any" is not allowed on the lineno of the class declaration.
Hi! Any work planned on this?
This was fixed in django-stubs 4.2.3.