Skip to content

Django-stubs > 5.1.1 causes VSCode to infer model field types as Any instead of expected types #2534

Open
@lucemia

Description

@lucemia

Bug report

What's wrong

After upgrading to django-stubs version > 5.1.1, VSCode's type intelligence no longer correctly infers the type of model fields. Specifically, it treats fields as Any instead of their expected types.

Reproduction

Minimal example:

from django.db import models

class Temp(models.Model):
    text = models.TextField()

t = Temp()
t.text  # Expected: str, but reported as Any in VSCode

Expected Behavior

  • django-stubs 5.1.1 correctly infers t.text as str in VSCode.
  • django-stubs > 5.1.1 incorrectly treats t.text as Any in VSCode.

Observations

  • Running mypy still shows str as expected.
  • Issue only affects VSCode’s type intelligence (Pylance/pyright).
  • Removing the py.typed file from the django-stubs folder fixes the issue, but the reason is unclear.
  • Downgrading django-stubs to 5.1.1 restores correct type inference.

How is that should be

VSCode should correctly infer the type of model fields, just like in django-stubs 5.1.1. The expected behavior is:

t.text  # Type should be inferred as str, not Any

System information

  • OS: Mac
  • python version: 3.11
  • django version: 5.1
  • mypy version: 1.13.0
  • django-stubs version: 5.1.3
  • django-stubs-ext version: 5.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpyrightRelated to pyright type checker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions