Implicitly concatenated strings treated as `str` instead of `typing.Literal`
The `psycopg.sql.SQL` class expects a literal string (aka, `typing.Literal`) as its parameter type. PyCharm respects this unless you pass an implicitly concatenated string literal. For example, the following does not elicit a warning:
psycopg.sql.SQL('SELECT * FROM public.reference')However, I use implicit string concatenation for longer queries since it is preferred over explicit string concatenation. The following elicits a “Expected type ‘LiteralString’, got ‘str’ instead" warning:
psycopg.sql.SQL(
'SELECT id, name, best81, best86, best87'
' FROM public.reference'
)
I rely on mypy for static type checking so this is more of an annoyance than problem for me. It would be nice to not have to disable the inspection though.
请先登录再写评论。
Hi Daveshawley,
I have created a ticket here PY-82680, assigned developer will take a look.
Please follow the issue for updates, feel free to vote and comment, and let us know if you need any help. If you're not familiar with YouTrack, please see https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications
🙏