Skip to content

Commit

Permalink
add FAQ entry regarding StrPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoettle committed Jan 12, 2023
1 parent c84e7f0 commit f8e5582
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ def foo(obj: object) -> None:
...
```

### Why am I getting incompatible argument type mentioning `_StrPromise`?

The lazy translation functions of Django (such as `gettext_lazy`) return a `Promise` instead of `str`. These two types [cannot be used interchangeably](https://github.com/typeddjango/django-stubs/pull/1139#issuecomment-1232167698). The return type of these functions was therefore [changed](https://github.com/typeddjango/django-stubs/pull/689) to reflect that.

If you encounter this error in your own code, use `StrPromise` or `StrOrPromise` from `django-stubs-ext`.

```python
from django.utils.translation import gettext_lazy as _

from django_stubs_ext import StrOrPromise

errors: list[StrOrPromise] = []
errors.add(_('Error message'))
```

If this is reported on Django code, please report an issue or open a pull request.

## Related projects

- [`awesome-python-typing`](https://github.com/typeddjango/awesome-python-typing) - Awesome list of all typing-related things in Python.
Expand Down

0 comments on commit f8e5582

Please sign in to comment.