django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

Model class definition error: Explicit "Any" is not allowed

Open sobolevn opened this issue 6 years ago • 3 comments

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.

sobolevn avatar Aug 25 '19 17:08 sobolevn

This might be related to https://github.com/typeddjango/django-stubs/issues/64

sobolevn avatar Aug 25 '19 18:08 sobolevn

Same issue here, reporting Explicite "Any" is not allowed on the lineno of the class declaration.

gerbyzation avatar Oct 31 '19 11:10 gerbyzation

Hi! Any work planned on this?

felixmeziere avatar Jun 28 '22 09:06 felixmeziere

This was fixed in django-stubs 4.2.3.

intgr avatar Jun 29 '23 17:06 intgr