Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve types of as_sql() and as_<engine>() methods #1315

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve types of as_sql() and as_<engine>() methods
intgr committed Jan 25, 2023
commit dad022c43b273b62fa6820b7f896ef265e3a6498
4 changes: 3 additions & 1 deletion django-stubs/contrib/gis/db/models/aggregates.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Aggregate
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType

class GeoAggregate(Aggregate):
is_extent: bool
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class Collect(GeoAggregate):
name: str
38 changes: 23 additions & 15 deletions django-stubs/contrib/gis/db/models/functions.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.mysql.compiler import SQLCompiler
intgr marked this conversation as resolved.
Show resolved Hide resolved
from django.db.models import Func
from django.db.models import Transform as StandardTransform

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

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

class OracleToleranceMixin:
tolerance: float
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class Area(OracleToleranceMixin, GeoFunc):
arity: int
@property
def output_field(self) -> Any: ...
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

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

class AsGML(GeoFunc):
geom_param_pos: Any
output_field: Any
def __init__(self, expression: Any, version: int = ..., precision: int = ..., **extra: Any) -> None: ...
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

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

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

class Centroid(OracleToleranceMixin, GeomOutputGeoFunc):
arity: int
@@ -83,8 +85,10 @@ class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
geom_param_pos: Any
spheroid: Any
def __init__(self, expr1: Any, expr2: Any, spheroid: Any | None = ..., **extra: Any) -> None: ...
def as_postgresql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_postgresql(
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
) -> _AsSqlType: ...
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

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

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

class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
spheroid: Any
def __init__(self, expr1: Any, spheroid: bool = ..., **extra: Any) -> None: ...
def as_postgresql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_postgresql(
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
) -> _AsSqlType: ...
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

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

class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
arity: int
def as_postgresql(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_sqlite(self, compiler: Any, connection: Any, **extra_context: Any) -> Any: ...
def as_postgresql(
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
) -> _AsSqlType: ...
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

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

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

class Union(OracleToleranceMixin, GeomOutputGeoFunc):
arity: int
4 changes: 2 additions & 2 deletions django-stubs/db/models/functions/text.pyi
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@ from django.db.models.sql.compiler import SQLCompiler, _AsSqlType

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

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

# Typo: `extra_conteNt`, remains in 4.0
class PostgreSQLSHAMixin:
def as_postgresql(
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_content: Any
self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn. That was my typo 😂 Thanks for fixing!

) -> _AsSqlType: ...

class Chr(Transform):
2 changes: 1 addition & 1 deletion django-stubs/db/models/sql/where.pyi
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class WhereNode(tree.Node):
resolved: bool
conditional: bool
def split_having(self, negated: bool = ...) -> tuple[WhereNode | None, WhereNode | None]: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Any: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ...
def get_group_by_cols(self, alias: str | None = ...) -> list[Expression]: ...
def relabel_aliases(self, change_map: dict[str | None, str]) -> None: ...
def clone(self) -> WhereNode: ...