paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
391 stars 67 forks source link

typing wrong for `G` function when `n` > 1 #163

Closed sasacocic closed 3 months ago

sasacocic commented 3 months ago

When you create models using G and you use n and it's greater than like in the example below the type information is incorrect. I would expect to get back list[Req] not Req. I've attached an image below to show this in vscode.

from my_djangoapp.models import Req
req = ddf.G(Req, 10)  
Screenshot 2024-07-25 at 6 29 04 PM

I'd be glad to put up a PR to fix this as it's a pretty easy fix.

A potential solution would be to just change the type definition although there might be a way to get better ergonomics than that

def get(model: typing.Type[INSTANCE_TYPE], n: int=1, ddf_lesson=None, **kwargs) -> INSTANCE_TYPE | list[INSTANCE_TYPE]:
paulocheque commented 3 months ago

A PR would be good!

sasacocic commented 3 months ago

@paulocheque I put up a PR: https://github.com/paulocheque/django-dynamic-fixture/pull/164/files

paulocheque commented 3 months ago

Cool! I will check/merge that.