File: test_formsets.yml

package info (click to toggle)
python-django-stubs 5.2.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,832 kB
  • sloc: python: 5,185; makefile: 15; sh: 8
file content (23 lines) | stat: -rw-r--r-- 975 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- case: inlineformset_factory
  main: |
    from typing import Any
    from typing_extensions import reveal_type
    from django import forms
    from myapp.models import Article, Category
    ArticleFS: type[forms.BaseInlineFormSet[Article, Category, Any]] = forms.inlineformset_factory(Category, Article)
    ArticleFS(instance=Article())  # E: Argument "instance" to "BaseInlineFormSet" has incompatible type "Article"; expected "Category | None"  [arg-type]
    fs = ArticleFS(instance=Category())
    reveal_type(fs.instance)  # N: Revealed type is "myapp.models.Category"
    reveal_type(fs.get_queryset())  # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Article, myapp.models.Article]"
  installed_apps:
    - myapp
  files:
    - path: myapp/__init__.py
    - path: myapp/models.py
      content: |
        from django.db import models

        class Article(models.Model):
            pass
        class Category(models.Model):
            pass