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

Error while passing gettext_lazy to arguments expecting strings #1137

Closed
hannseman opened this issue Aug 29, 2022 · 0 comments · Fixed by #1139
Closed

Error while passing gettext_lazy to arguments expecting strings #1137

hannseman opened this issue Aug 29, 2022 · 0 comments · Fixed by #1139
Labels
bug Something isn't working

Comments

@hannseman
Copy link
Contributor

hannseman commented Aug 29, 2022

Bug report

What's wrong

Errors when passing gettext_lazy strings to parameters expecting strings like verbose_name and help_text on model fields:

error: Argument "verbose_name" to "PositiveBigIntegerField" has incompatible type
"_StrPromise"; expected "Optional[str]"  [arg-type]
            null=True, blank=True, verbose_name=_("number")

(where _ is defined as from django.utils.translation import gettext_lazy as _)

This was introduced in #689

How is that should be

_StrPromise should be able to be passed as a str.

System information

  • OS: MacOS 12.4
  • python version: 3.10
  • django version: 4.1
  • mypy version: 0.971
  • django-stubs version: master
  • django-stubs-ext version: master
@hannseman hannseman added the bug Something isn't working label Aug 29, 2022
PIG208 added a commit to PIG208/django-stubs that referenced this issue Aug 29, 2022
sobolevn pushed a commit that referenced this issue Sep 19, 2022
…1139)

* Broaden type annotation for verbose_name(_plural) to accept lazystr.

Fixes #1137.

Signed-off-by: Zixuan James Li <[email protected]>

* Broaden type annotation for help_text to accept lazystr.

Signed-off-by: Zixuan James Li <[email protected]>

* Broaden type annotation for ValidationError to accept lazystr.

Signed-off-by: Zixuan James Li <[email protected]>

* Broaden type annotation for label to accept lazystr.

Signed-off-by: Zixuan James Li <[email protected]>

* Add StrPromise and StrOrPromise aliases to django_stubs_ext.

We make StrPromise and StrOrPromise available via django_stubs_ext so
that conditional imports with TYPE_CHECKING is not required.
These aliases fall back to Promise or Union[str, Promise]
when not TYPE_CHECKING.

Signed-off-by: Zixuan James Li <[email protected]>

Signed-off-by: Zixuan James Li <[email protected]>
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.

1 participant