Description:
When using a connection pool in the python MySQL connector, the PooledMySQLConnection class is said to be a clone (functionally) of the MySQLConnection class with a couple differences such as how close() and config() methods work.
Yet, PooledMySQLConnection does not extend MySQLConnection, and there is no special typing on the class. Due to this, autocompletion does not work on this class.
How to repeat:
Simply download and import mysql-connector-python version 9.3.0 from PyPI and create a pool.Running get_connection() on the pool acts as expected but if you attempt to create a cursor from that connection with cnx.cursor() you will note that it *does* work, but does not show any autocomplete as you would expect.
pseudo-code example:
pool = MySQLConnectionPool(args)
connection = pool.get_connection()
cursor = connection.cursor() <- this will not autocomplete. nor will any other MySQLConnection method despite working functionally.
I am using VSCode as an editor.
Suggested fix:
Ideally, in line 358 of pooling.py under the mysql.connector package, make the PooledMySQLConnection class extend MySQLConnection and handle things that way
Anything would be fine, as long as the methods accessible from an instance of MySQLConnection are available from PooledMySQLConnection.
My solution was was to create my own class extending the base mysql.connection.pooling.MySQLConnectionPool, MySQLConnectionPoolCustom(pooling.MySQLConnectionPool), and overrode the get_connection() method to work like so:
def get_connection(self) -> connector.MySQLConnection:
return super().get_connection()
and that works for me, though of course the docstrings are slightly off. This could be solved with a custom docstring on the overridden method describing the changes between a pooled connection and a standard one (close() and config(), etc.)
hope all of this helps - its a relatively minor thing but one that would streamline development a lot if it was just included by default. All good editors these days use code autocompletion and proper typing is essential for it to work.