Open DanieleIsoni opened 6 months ago
https://github.com/typeddjango/django-stubs/blob/9880684a36f70e61124115a296e34cd0df15e3f1/django-stubs/contrib/admin/utils.pyi#L57 In the code above, the nested method returns a simple list[Model], while it is a bit more complex than that.
nested
list[Model]
It should return something like list[RecursiveModelList] with RecursiveModelList being:
list[RecursiveModelList]
RecursiveModelList: TypeAlias = Model | list['RecursiveModelList']
You can verify by running the following and checking what's in collected_instances:
collected_instances
class Author(Model): name = CharField(max_length=100) class BooksCollection(Model): name = CharField(max_length=100) author = ForeignKey(Author, on_delete=CASCADE) class Book(Model): name = CharField(max_length=100) collection = ForeignKey(BooksCollection, on_delete=CASCADE) author = Author.objects.create(name="Author") collection = BooksCollection.objects.create(name="Author's life adventures", author=author) book = Book.objects.create(name="Author's childhood", collection=collection) collector = NestedObjects(using="default") collector.collect([author]) collected_instances = collector.nested()
python
django
mypy
django-stubs
django-stubs-ext
Or list[Any] (if recursion is problematic).
list[Any]
Bug report
What's wrong
https://github.com/typeddjango/django-stubs/blob/9880684a36f70e61124115a296e34cd0df15e3f1/django-stubs/contrib/admin/utils.pyi#L57 In the code above, the
nested
method returns a simplelist[Model]
, while it is a bit more complex than that.How is that should be
It should return something like
list[RecursiveModelList]
with RecursiveModelList being:How to reproduce
You can verify by running the following and checking what's in
collected_instances
:System information
python
version: 2.11.2django
version: 4.2.10mypy
version: 1.8.0django-stubs
version: 4.2.7django-stubs-ext
version: 4.2.7