sbdchd / django-types

:doughnut: Type stubs for Django
MIT License
202 stars 63 forks source link

Set correct types if `upload_to` is a function #105

Closed joseferben closed 2 years ago

joseferben commented 2 years ago

https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.FileField.upload_to

        if callable(self.upload_to):
            filename = self.upload_to(instance, filename)
        else:
            dirname = datetime.datetime.now().strftime(str(self.upload_to))
            filename = posixpath.join(dirname, filename)
sbdchd commented 2 years ago

Actually, looking at the types it seems a little tricky. The return type seems more flexible than just str, like path and bytes also work for the calls that use the value