You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a first step, I would suggest changing the semantic analyzer to treat LiteralString simply as an alias for str. That's not correct, but it will be enough to enable third-party libraries and typeshed to start using LiteralString.
and each type checker would have a list of recognized typing feature flags. For this specific case my hopeful guess is work involved isn't large but main reason I'd be interested in this is to make it possible to have stuff like,
@hmc-cs-mdrissi, that might be nice, but we'd require agreement from all major type checkers to do something like that (such proposals should be discussed in the https://github.com/python/typing issue tracker rather than this one). For now, @JelleZijlstra's suggestion is probably easier.
just to let you know, I have introduced LiteralString in psycopg 3.1 codebase and I have used pyre as a one-off tool to identify and fix internal usage of non-literal strings (psycopg/psycopg#323). Of course the real deal will be for people using mypy to verify that their queries used with psycopg are safe.
I would like to throw at you an use case we could be interested in: to use mypy as a library to verify at import time or runtime that the user is not doing anything untoward. If you think that something of that sort might happen, please keep us informed.
Note that mypy has currently reverted python/typeshed#7725 in its vendored copy of typeshed (#13093, #13091) in order to avoid some inference regressions (#12982 (comment)). This is fine because mypy currently does not actually support LiteralString.
Activity
hmc-cs-mdrissi commentedon Apr 10, 2022
Hmm, an alternative idea would be if typing_extensions/typing had feature flags like,
typing.PEP_675_SUPPORTED then typeshed could add to typing_extensions.pyi,
and each type checker would have a list of recognized typing feature flags. For this specific case my hopeful guess is work involved isn't large but main reason I'd be interested in this is to make it possible to have stuff like,
where I'm guessing even basic support will be harder.
I'm assuming most feature flags would correspond to one typing pep.
AlexWaygood commentedon Apr 10, 2022
@hmc-cs-mdrissi, that might be nice, but we'd require agreement from all major type checkers to do something like that (such proposals should be discussed in the https://github.com/python/typing issue tracker rather than this one). For now, @JelleZijlstra's suggestion is probably easier.
Recognise LiteralString as str
Recognise LiteralString as str (#12559)
dvarrazzo commentedon Jun 29, 2022
Hello,
just to let you know, I have introduced
LiteralStringin psycopg 3.1 codebase and I have used pyre as a one-off tool to identify and fix internal usage of non-literal strings (psycopg/psycopg#323). Of course the real deal will be for people using mypy to verify that their queries used with psycopg are safe.I would like to throw at you an use case we could be interested in: to use mypy as a library to verify at import time or runtime that the user is not doing anything untoward. If you think that something of that sort might happen, please keep us informed.
Thank you!
hauntsaninja commentedon Jul 16, 2022
Note that mypy has currently reverted python/typeshed#7725 in its vendored copy of typeshed (#13093, #13091) in order to avoid some inference regressions (#12982 (comment)). This is fine because mypy currently does not actually support LiteralString.
FinchPowers commentedon Aug 9, 2023
Good day!
I'm wondering if there is an update regarding the inclusion of LiteralString in mypy?
Thanks!
use LiteralString (although mypy hasn't supported it yet)
rupeshs commentedon Nov 29, 2024
Any update on this?
LiteralStringis seen as "broader or same" asstr#18584 as a duplicate of this issueCoolCat467 commentedon Dec 15, 2025
Updates ping again