You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cannot use the class returned from inlineformset_factory as a baseclase for creating another class, failing test:
- case: inlineformset_factory_extended
main: |
from typing import Any, 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 "Optional[Category]"
class CustomArticleFS(ArticleFS): # It will throw a "ArticleFS" is not a valid type error here.
def __init__(self, *args, **kwargs):
print('hi')
super().__init__(*args, **kwargs)
fs = CustomArticleFS(instance=Category())
reveal_type(fs.instance) # N: Revealed type is "myapp.models.Category"
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
Bug report
What's wrong
Cannot use the class returned from inlineformset_factory as a baseclase for creating another class, failing test:
@sterliakov has provided some very helpful context here in this comment
#976 (comment)
related issue on mypy linked y @sterliakov: python/mypy#2813
related question on stackoverflow: https://stackoverflow.com/questions/59634937/variable-foo-class-is-not-valid-as-type-but-why
How is that should be
Should be able to use a dynamic class as baseclass for creating new classes, I guess as long as that baseclass's type is known.
System information
python
version: 3.8django
version: used django-stubs environment at this commit hashmypy
version: 0.961django-stubs
version: 1.12.0django-stubs-ext
version: 0.4.3The text was updated successfully, but these errors were encountered: