mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-15 16:27:09 +08:00
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:
13
tests/typecheck/db/test_connection.yml
Normal file
13
tests/typecheck/db/test_connection.yml
Normal 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'
|
||||
Reference in New Issue
Block a user