Skip to content

Commit a1c848f

Browse files
cherry-pick upstream pr typeddjango#2195 (#11)
Co-authored-by: Noam Kushinsky <[email protected]>
1 parent 3a4ccd4 commit a1c848f

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
from typing import Any, ClassVar
22

33
from django.db.models import Func
4+
from django.db.models.expressions import Combinable
45
from django.db.models.fields import Field
56
from django.db.models.fields.json import JSONField
67

78
class Cast(Func):
8-
def __init__(self, expression: Any, output_field: str | Field) -> None: ...
9+
def __init__(self, expression: Combinable | str, output_field: str | Field) -> None: ...
910

1011
class Coalesce(Func): ...
1112

1213
class Collate(Func):
13-
def __init__(self, expression: Any, collation: str) -> None: ...
14+
def __init__(self, expression: Combinable | str, collation: str) -> None: ...
1415

1516
class Greatest(Func): ...
1617

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing import Any, ClassVar
44
from django.db import models
55
from django.db.backends.base.base import BaseDatabaseWrapper
66
from django.db.models import Func, Transform
7-
from django.db.models.expressions import Expression
7+
from django.db.models.expressions import Combinable
88
from django.db.models.fields import Field
99
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
1010

@@ -16,7 +16,7 @@ class Extract(TimezoneMixin, Transform):
1616
lookup_name: str
1717
output_field: ClassVar[models.IntegerField]
1818
def __init__(
19-
self, expression: Any, lookup_name: str | None = ..., tzinfo: Any | None = ..., **extra: Any
19+
self, expression: Combinable | str, lookup_name: str | None = ..., tzinfo: Any | None = ..., **extra: Any
2020
) -> None: ...
2121

2222
class ExtractYear(Extract): ...
@@ -41,14 +41,14 @@ class TruncBase(TimezoneMixin, Transform):
4141
tzinfo: Any
4242

4343
def __init__(
44-
self, expression: Expression, output_field: Field | None = ..., tzinfo: tzinfo | None = ..., **extra: Any
44+
self, expression: Combinable | str, output_field: Field | None = ..., tzinfo: tzinfo | None = ..., **extra: Any
4545
) -> None: ...
4646
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]
4747

4848
class Trunc(TruncBase):
4949
def __init__(
5050
self,
51-
expression: Expression,
51+
expression: Combinable | str,
5252
kind: str,
5353
output_field: Field | None = ...,
5454
tzinfo: tzinfo | None = ...,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from django.db.models.expressions import Func
1+
from typing import Any
2+
3+
from django.db.models.expressions import Combinable, Func
24
from django.db.models.functions.mixins import FixDecimalInputMixin, NumericOutputFieldMixin
35
from django.db.models.lookups import Transform
46

@@ -19,7 +21,10 @@ class Mod(FixDecimalInputMixin, NumericOutputFieldMixin, Func): ...
1921
class Pi(NumericOutputFieldMixin, Func): ...
2022
class Power(NumericOutputFieldMixin, Func): ...
2123
class Radians(NumericOutputFieldMixin, Transform): ...
22-
class Round(Transform): ...
24+
25+
class Round(Transform):
26+
def __init__(self, expression: Combinable | str, precision: int = ..., **extra: Any) -> None: ...
27+
2328
class Sin(NumericOutputFieldMixin, Transform): ...
2429
class Sqrt(NumericOutputFieldMixin, Transform): ...
2530
class Tan(NumericOutputFieldMixin, Transform): ...

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Concat(Func):
3232

3333
class Left(Func):
3434
output_field: ClassVar[models.CharField]
35-
def __init__(self, expression: Expression | str, length: Expression | int, **extra: Any) -> None: ...
35+
def __init__(self, expression: Combinable | str, length: Expression | int, **extra: Any) -> None: ...
3636
def get_substr(self) -> Substr: ...
3737
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
3838
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
@@ -46,7 +46,7 @@ class Lower(Transform): ...
4646
class LPad(Func):
4747
output_field: ClassVar[models.CharField]
4848
def __init__(
49-
self, expression: Expression | str, length: Expression | int | None, fill_text: Expression = ..., **extra: Any
49+
self, expression: Combinable | str, length: Expression | int | None, fill_text: Expression = ..., **extra: Any
5050
) -> None: ...
5151

5252
class LTrim(Transform): ...
@@ -59,7 +59,7 @@ class Ord(Transform):
5959

6060
class Repeat(Func):
6161
output_field: ClassVar[models.CharField]
62-
def __init__(self, expression: Expression | str, number: Expression | int | None, **extra: Any) -> None: ...
62+
def __init__(self, expression: Combinable | str, number: Expression | int | None, **extra: Any) -> None: ...
6363
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
6464

6565
class Replace(Func):
@@ -91,7 +91,7 @@ class StrIndex(Func):
9191
class Substr(Func):
9292
output_field: ClassVar[models.CharField]
9393
def __init__(
94-
self, expression: Expression | str, pos: Expression | int, length: Expression | int | None = ..., **extra: Any
94+
self, expression: Combinable | str, pos: Expression | int, length: Expression | int | None = ..., **extra: Any
9595
) -> None: ...
9696
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
9797
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

scripts/stubtest/allowlist_todo.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,6 @@ django.db.models.functions.NullIf.as_oracle
10601060
django.db.models.functions.Pi.as_oracle
10611061
django.db.models.functions.Radians.as_oracle
10621062
django.db.models.functions.Random
1063-
django.db.models.functions.Round.__init__
10641063
django.db.models.functions.comparison.Cast.as_mysql
10651064
django.db.models.functions.comparison.Cast.as_oracle
10661065
django.db.models.functions.comparison.Cast.as_postgresql
@@ -1084,7 +1083,6 @@ django.db.models.functions.math.Degrees.as_oracle
10841083
django.db.models.functions.math.Pi.as_oracle
10851084
django.db.models.functions.math.Radians.as_oracle
10861085
django.db.models.functions.math.Random
1087-
django.db.models.functions.math.Round.__init__
10881086
django.db.models.functions.mixins.FixDecimalInputMixin.as_postgresql
10891087
django.db.models.functions.mixins.FixDurationInputMixin.as_mysql
10901088
django.db.models.functions.mixins.FixDurationInputMixin.as_oracle

0 commit comments

Comments
 (0)