Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gettext_lazy should return a Promise object #688

Closed
PIG208 opened this issue Aug 11, 2021 · 2 comments · Fixed by #689
Closed

gettext_lazy should return a Promise object #688

PIG208 opened this issue Aug 11, 2021 · 2 comments · Fixed by #689
Labels
bug Something isn't working

Comments

@PIG208
Copy link
Contributor

PIG208 commented Aug 11, 2021

Bug report

The type annotation added in #126 is incorrect.

What's wrong

from django.utils.translation import gettext_lazy, ngettext_lazy, pgettext_lazy, ugettext_lazy
from django.utils.functional import Promise

a = gettext_lazy("Help")
b = ugettext_lazy("Help")
c = pgettext_lazy("Help")
d = ngettext_lazy("help", "helps")
e = ugettext_lazy("Help")

assert isinstance(a, Promise)
assert isinstance(b, Promise)
assert isinstance(c, Promise)
assert isinstance(d, Promise)
assert isinstance(e, Promise)

How is that should be

For all lazy functions above, django-stubs consider the return type to be str, which is actually incorrect. All of them are in fact instances of django.utils.functional.Promise

@PIG208 PIG208 added the bug Something isn't working label Aug 11, 2021
@sobolevn
Copy link
Member

@PIG208 PRs are welcome!

PIG208 added a commit to PIG208/django-stubs that referenced this issue Aug 11, 2021
Django uses a proxy method for lazy translation functions that actually
returns instances of `Promise` instead of `str`.

Fixes typeddjango#688.
@PIG208
Copy link
Contributor Author

PIG208 commented Aug 11, 2021

@sobolevn Just created a PR for this :)

PIG208 added a commit to PIG208/django-stubs that referenced this issue Jun 29, 2022
Django uses a proxy method for lazy translation functions that actually
returns instances of `Promise` instead of `str`.

Fixes typeddjango#688.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants