Skip to content

Commit 5d3aa2d

Browse files
committed
add FAQ entry regarding StrPromise
1 parent c84e7f0 commit 5d3aa2d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ def foo(obj: object) -> None:
291291
...
292292
```
293293

294+
### Why am I getting incompatible argument type mentioning `_StrPromise`?
295+
296+
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.
297+
298+
If you encounter this error in your own code, you can either cast the `Promise` to `str` (causing the translation to be evaluated), or use the `StrPromise` or `StrOrPromise` types from `django-stubs-ext` in type hints. Which solution to choose depends depends on the particular case. See [working with lazy translation objects] in the Django documentation for more information.
299+
300+
If this is reported on Django code, please report an issue or open a pull request to fix the type hints.
301+
294302
## Related projects
295303

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

0 commit comments

Comments
 (0)