Skip to content

Commit 32e5ebc

Browse files
intgrngnpope
andauthored
Improve types of as_sql() and as_<engine>() methods (#1315)
Co-authored-by: Nick Pope <[email protected]>
1 parent e6d65d2 commit 32e5ebc

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

django-stubs/contrib/gis/db/backends/utils.pyi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from collections.abc import Mapping, Sequence
12
from typing import Any
23

4+
from django.contrib.gis.db.models.lookups import GISLookup
5+
from django.db.backends.base.base import BaseDatabaseWrapper
36
from django.db.models.sql.compiler import _AsSqlType
47

58
class SpatialOperator:
@@ -9,4 +12,10 @@ class SpatialOperator:
912
def __init__(self, op: Any | None = ..., func: Any | None = ...) -> None: ...
1013
@property
1114
def default_template(self) -> Any: ...
12-
def as_sql(self, connection: Any, lookup: Any, template_params: Any, sql_params: Any) -> _AsSqlType: ...
15+
def as_sql(
16+
self,
17+
connection: BaseDatabaseWrapper,
18+
lookup: GISLookup,
19+
template_params: Mapping[str, Any],
20+
sql_params: Sequence[Any],
21+
) -> _AsSqlType: ...

django-stubs/contrib/gis/db/models/aggregates.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from typing import Any
22

3+
from django.db.backends.base.base import BaseDatabaseWrapper
34
from django.db.models import Aggregate
5+
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
46

57
class GeoAggregate(Aggregate):
68
is_extent: bool
7-
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
9+
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
810

911
class Collect(GeoAggregate):
1012
name: str

django-stubs/contrib/gis/db/models/functions.pyi

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Any
22

3+
from django.db.backends.base.base import BaseDatabaseWrapper
34
from django.db.models import Func
45
from django.db.models import Transform as StandardTransform
6+
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
57

68
NUMERIC_TYPES: Any
79

@@ -17,17 +19,17 @@ class GeomOutputGeoFunc(GeoFunc):
1719
def output_field(self) -> Any: ...
1820

1921
class SQLiteDecimalToFloatMixin:
20-
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
22+
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
2123

2224
class OracleToleranceMixin:
2325
tolerance: float
24-
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
26+
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
2527

2628
class Area(OracleToleranceMixin, GeoFunc):
2729
arity: int
2830
@property
2931
def output_field(self) -> Any: ...
30-
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
32+
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
3133

3234
class Azimuth(GeoFunc):
3335
output_field: Any
@@ -39,13 +41,13 @@ class AsGeoJSON(GeoFunc):
3941
def __init__(
4042
self, expression: Any, bbox: bool = ..., crs: bool = ..., precision: int = ..., **extra: Any
4143
) -> None: ...
42-
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
44+
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
4345

4446
class AsGML(GeoFunc):
4547
geom_param_pos: Any
4648
output_field: Any
4749
def __init__(self, expression: Any, version: int = ..., precision: int = ..., **extra: Any) -> None: ...
48-
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
50+
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
4951

5052
class AsKML(GeoFunc):
5153
output_field: Any
@@ -65,7 +67,7 @@ class AsWKT(GeoFunc):
6567

6668
class BoundingCircle(OracleToleranceMixin, GeomOutputGeoFunc):
6769
def __init__(self, expression: Any, num_seg: int = ..., **extra: Any) -> None: ...
68-
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
70+
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
6971

7072
class Centroid(OracleToleranceMixin, GeomOutputGeoFunc):
7173
arity: int
@@ -83,8 +85,10 @@ class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
8385
geom_param_pos: Any
8486
spheroid: Any
8587
def __init__(self, expr1: Any, expr2: Any, spheroid: Any | None = ..., **extra: Any) -> None: ...
86-
def as_postgresql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
87-
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
88+
def as_postgresql(
89+
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
90+
) -> _AsSqlType: ...
91+
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
8892

8993
class Envelope(GeomOutputGeoFunc):
9094
arity: int
@@ -95,7 +99,7 @@ class ForcePolygonCW(GeomOutputGeoFunc):
9599
class GeoHash(GeoFunc):
96100
output_field: Any
97101
def __init__(self, expression: Any, precision: Any | None = ..., **extra: Any) -> None: ...
98-
def as_mysql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
102+
def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
99103

100104
class GeometryDistance(GeoFunc):
101105
output_field: Any
@@ -111,13 +115,15 @@ class Intersection(OracleToleranceMixin, GeomOutputGeoFunc):
111115
class IsValid(OracleToleranceMixin, GeoFuncMixin, StandardTransform):
112116
lookup_name: str
113117
output_field: Any
114-
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
118+
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
115119

116120
class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
117121
spheroid: Any
118122
def __init__(self, expr1: Any, spheroid: bool = ..., **extra: Any) -> None: ...
119-
def as_postgresql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
120-
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
123+
def as_postgresql(
124+
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
125+
) -> _AsSqlType: ...
126+
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
121127

122128
class LineLocatePoint(GeoFunc):
123129
output_field: Any
@@ -140,8 +146,10 @@ class NumPoints(GeoFunc):
140146

141147
class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
142148
arity: int
143-
def as_postgresql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
144-
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
149+
def as_postgresql(
150+
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
151+
) -> _AsSqlType: ...
152+
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
145153

146154
class PointOnSurface(OracleToleranceMixin, GeomOutputGeoFunc):
147155
arity: int
@@ -163,7 +171,7 @@ class Transform(GeomOutputGeoFunc):
163171
def __init__(self, expression: Any, srid: Any, **extra: Any) -> None: ...
164172

165173
class Translate(Scale):
166-
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
174+
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
167175

168176
class Union(OracleToleranceMixin, GeomOutputGeoFunc):
169177
arity: int

django-stubs/db/models/functions/text.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ from typing import Any
33
from django.db import models
44
from django.db.backends.base.base import BaseDatabaseWrapper
55
from django.db.models import Func, Transform
6-
from django.db.models.expressions import Combinable, Expression, F, Value
6+
from django.db.models.expressions import Combinable, Expression, Value
77
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
88

9-
# Typo: `extra_conteNt`, remains in 4.0
109
class MySQLSHA2Mixin:
11-
def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_content: Any) -> _AsSqlType: ...
10+
def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
1211

1312
class OracleHashMixin:
1413
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
1514

16-
# Typo: `extra_conteNt`, remains in 4.0
1715
class PostgreSQLSHAMixin:
1816
def as_postgresql(
19-
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_content: Any
17+
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
2018
) -> _AsSqlType: ...
2119

2220
class Chr(Transform):

django-stubs/db/models/sql/where.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WhereNode(tree.Node):
1717
resolved: bool
1818
conditional: bool
1919
def split_having(self, negated: bool = ...) -> tuple[WhereNode | None, WhereNode | None]: ...
20-
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Any: ...
20+
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ...
2121
def get_group_by_cols(self, alias: str | None = ...) -> list[Expression]: ...
2222
def relabel_aliases(self, change_map: dict[str | None, str]) -> None: ...
2323
def clone(self) -> WhereNode: ...

0 commit comments

Comments
 (0)