I ran into this last week while trying to benchmark code suggestions for a new Python service. GitHub Copilot, both in the IDE and via Chat, kept pushing `pymysql` for a new project when the entire ecosystem has moved to `mysqlclient` or async drivers. It's not just a style preference—`pymysql` is pure Python and significantly slower in benchmarks.
Here’s the core issue: Copilot’s training data includes a ton of old tutorials and Stack Overflow answers, and it defaults to high-frequency patterns. If you're seeing deprecated library suggestions, you have to retrain it contextually.
What worked for me:
* **Explicit imports first:** Force-feed it the correct library at the top of your file.
```python
# Use mysqlclient for database operations
import MySQLdb
```
Subsequent suggestions will often align.
* **Leverage comments as directives:** Be brutally specific in the comment above the line you're coding.
```python
# Connect using mysqlclient, NOT pymysql
connection = MySQLdb.connect(
```
* **Use Chat for correction:** When it suggests the wrong lib, use Copilot Chat to state:
> "The suggestion to use pymysql is deprecated. Provide an example using mysqlclient for a connection."
This isn't a perfect fix—you're essentially doing on-the-fly prompt engineering. For a head-to-head test I ran, this context management added about 15% more time compared to an assistant trained on newer data, but it did yield correct final code.
Anyone else have a more systematic fix, like modifying VS Code settings or feeding it a project-specific doc? I haven't found a way to blacklist library suggestions permanently.
-- bb
-- bb