Improve hints for database connections (DatabaseWrapper) (#612)

* `django.db.{connection, connections, router}` are now hinted -- including `ConnectionHandler` and `ConnectionRouter` classes.
* Several improvements to `BaseDatabaseWrapper` attribute hints.
* In many places, database connections were hinted as `Any`, which I changed to `BaseDatabaseWrapper`.
* In a few places I added additional `SQLCompiler` hints.
* Minor tweaks to nearby code.
This commit is contained in:
Marti Raudsepp
2021-05-13 20:22:35 +03:00
committed by GitHub
parent d1dd95181a
commit 45f6dc0362
29 changed files with 166 additions and 105 deletions

View File

@@ -0,0 +1,13 @@
- case: raw_default_connection
main: |
from django.db import connection
with connection.cursor() as cursor:
reveal_type(cursor) # N: Revealed type is 'django.db.backends.utils.CursorWrapper'
cursor.execute("SELECT %s", [123])
- case: raw_connections
main: |
from django.db import connections
reveal_type(connections["test"]) # N: Revealed type is 'django.db.backends.base.base.BaseDatabaseWrapper'
for connection in connections.all():
with connection.cursor() as cursor:
reveal_type(cursor) # N: Revealed type is 'django.db.backends.utils.CursorWrapper'