-
-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support cursor.execute(psycopg2.sql.Composable) #1029
Support cursor.execute(psycopg2.sql.Composable) #1029
Conversation
50254f3
to
a4c8ebf
Compare
Strictly speaking, should we also account for other backends that might not support |
@PIG208 Erring on the side of accepting things that might or might not be accepted at runtime is a fine way for type stubs to account for that (and probably the only way in this case). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 👍
a4c8ebf
to
1cf8dfc
Compare
Updated. |
@@ -13,6 +27,14 @@ else: | |||
|
|||
logger: Any | |||
|
|||
# Protocol matching psycopg2.sql.Composable, to avoid depending psycopg2 | |||
class _Composable(Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we depend on types-psycopg2
? What do you think?
Refs #114
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A risk in that approach is that typeshed packages are obsoleted when the corresponding upstream packages add type annotations. In fact, psycopg3 (psycopg on PyPI) already has upstream type annotations, and we’ll want to support its version of Composable
, which satisfies the same protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 👾 ✨
Can you please resolve a conflict? I've merged something that broke this file |
In addition to str, PostgreSQL cursors accept the psycopg2.sql.Composable type, which is useful for guarding against SQL injections when building raw queries that can’t be parameterized in the normal way (e.g. interpolating identifiers). In order to avoid reintroducing a dependency on psycopg2, we define a Protocol that matches psycopg2.sql.Composable. Documentation: https://www.psycopg.org/docs/sql.html Related: python/typeshed#7494 Signed-off-by: Anders Kaseorg <andersk@mit.edu>
1cf8dfc
to
376406c
Compare
No problem, resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again 😊
In addition to
str
, PostgreSQL cursors accept thepsycopg2.sql.Composable
type, which is useful for guarding against SQL injections when building raw queries that can’t be parameterized in the normal way (e.g. interpolating identifiers).In order to avoid reintroducing a dependency on
psycopg2
, we define aProtocol
that matchespsycopg2.sql.Composable
.Documentation: https://www.psycopg.org/docs/sql.html
Related: python/typeshed#7494