-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Pymysql cursor types and fetching return types #5652
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
Conversation
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.
I haven't compared with the implementation, but the changes look reasonable. Especially getting rid of the response unions. Two remarks below.
Also, could you also update the version in METADATA.toml
?
I'm having some problems with this, but I'm posting here instead of creating a new issue in case I'm doing something dumb. I'm currently writing some typed code that uses a I was able to fix this either by patching pymysql to use a generic Connection, or by removing the generic from my type signature. The former solution of course makes the code much harder to maintain, and would require a fork of pymysql specifically for this project, at least until pymysql adopts python 3.10 or 3.7 (See PyMySQL/PyMySQL#953). The later causes my typechecker to complain very loudly about how Connection is supposed to be a generic, and also removes the benefit of having the generic in the first place. Is there a solution to this that doesn't require either leaving a type error in the code or forking pymysql? |
On 3.7+, add to beginning of file: from __future__ import annotations This tells Python to not evaluate the type annotations, so that they are just for the type checker. It also means that you can also use |
Oh thank you so much! That's perfect! |
Fixes #5567 so that
Cursor
andDictCursor
no longer return annoying unions. I also got rid of severalOptional
s. In those methods, I looked at the source code and I triedselect * from foo
on a local test database, and couldn't get it to returnNone
.I also made
Connection
generic, so that when you create a connection, it remembers which cursor class you want to use. You can still customize this by passing a custom class to.cursor()
.