pyre-check
pyre-check copied to clipboard
Python stdlib `string.Formatter` doesn't understand `LiteralString`
Hello,
I have tried to use pyre to introduce LiteralString in psycopg 3 codebase.
I could fix all the internal usage of LiteralString, however, several methods of string.Formatter might be considered returning LiteralString on LiteralString input.
See: https://github.com/psycopg/psycopg/blob/600d6dfaf1366d2eca4486f7686c57da88f2b807/psycopg/psycopg/sql.py#L248-L251
This is more likely a typeshed issue rather than pyre. However I don't know the relation between the two and how experimental the use of LiteralString is. So I'm leaving this mostly as a FYI and in case you will want to propose something to typeshed.
Thank you very much!
Please see the related issue https://github.com/psycopg/psycopg/issues/323
The OP also opened a ticket to typeshed at https://github.com/python/typeshed/issues/8195
Thanks for letting us know!
At this point my guess is that Pyre won't need to do anything except bump our vendored typeshed stubs once the problem is fixed in upstream repositories, we ought to work out-of-the box against correct stubs. Feel free to ping us once that has been done, and if there are still problems we can circle back and figure out why.
https://github.com/python/typeshed/pull/8268 is landed. @stroxler and chance of a typeshed upgrade + pyre release so we can close out this issue?
Would the typeshed upgrade allow "from typing import LiteralString" to work?
PEP 675 implies should.
As a side note, "import typing" and "from typing_extensions import LiteralString" seem to work.
PS: I only have a basic understanding of Python.
from typing import LiteralString will work only if you are on Python 3.11 or higher. from typing_extensions import LiteralString works on all supported versions (3.7+).
Ahh, thanks @JelleZijlstra, it does work on my local machine (with 3.11); and I assume https://pyre-check.org/play will be updated at some point in the future.