Skip to content

Conversation

sshishov
Copy link
Contributor

Use _StrPromise instead of _StrOrPromise for format_lazy return type.

Closes #2840

Sergei Shishov and others added 2 commits September 26, 2025 16:47
Use `_StrPromise` instead of `_StrOrPromise` for `format_lazy` return type.

Signed-off-by: Sergei Shishov <sergei.shishov@wafeq.com>
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, it can return str

In [1]: from django.utils.text import format_lazy

In [2]: format_lazy('a{0}', 'b')
Out[2]: 'ab'

@sshishov
Copy link
Contributor Author

HI @sobolevn , it seems it just does not have the safety-net. But yeah if it can accept str and return str then we have to type it properly. We can close my MR with the statement that Working As Expected.

It is just useless to use format_lazy for non-lazy objects, you can use f-string or str.format instead.

To manage mypy-error in our code we will add the internal assert then, which should fail on dev runtime for us. It is also suitable 👍

-- Sergei

@sobolevn
Copy link
Member

Maybe we can use overloads?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

The function format_lazy should return _StrPromise
2 participants