Repository navigation
Pymysql cursor types and fetching return types - #5652
Conversation
srittau
left a comment
There was a problem hiding this comment.
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 annotationsThis 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
CursorandDictCursorno longer return annoying unions. I also got rid of severalOptionals. In those methods, I looked at the source code and I triedselect * from fooon a local test database, and couldn't get it to returnNone.I also made
Connectiongeneric, 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().