Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 20 additions & 1 deletion django-stubs/db/models/functions/datetime.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from datetime import tzinfo
from typing import Any, ClassVar

from django.db import models
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Func, Transform
from django.db.models.expressions import Expression
from django.db.models.fields import Field
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType

class TimezoneMixin:
tzinfo: Any
Expand Down Expand Up @@ -33,7 +38,21 @@ class TruncBase(TimezoneMixin, Transform):
kind: str
tzinfo: Any

class Trunc(TruncBase): ...
def __init__(
self, expression: Expression, output_field: Field | None = ..., tzinfo: tzinfo | None = ..., **extra: Any
) -> None: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]

class Trunc(TruncBase):
def __init__(
self,
expression: Expression,
Copy link
Contributor

Choose a reason for hiding this comment

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

the types on expression do not match django.db.expressions.Func which currently has this typed as Any -- notably these expressions go through parsing and (at the very least) accept str as well

kind: str,
output_field: Field | None = ...,
tzinfo: tzinfo | None = ...,
**extra: Any,
) -> None: ...

class TruncYear(TruncBase): ...
class TruncQuarter(TruncBase): ...
class TruncMonth(TruncBase): ...
Expand Down
8 changes: 0 additions & 8 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,6 @@ django.db.models.functions.Pi.as_oracle
django.db.models.functions.Radians.as_oracle
django.db.models.functions.Random
django.db.models.functions.Round.__init__
django.db.models.functions.Trunc.__init__
django.db.models.functions.TruncDate.as_sql
django.db.models.functions.TruncTime.as_sql
django.db.models.functions.comparison.Cast.as_mysql
django.db.models.functions.comparison.Cast.as_oracle
django.db.models.functions.comparison.Cast.as_postgresql
Expand All @@ -1079,12 +1076,7 @@ django.db.models.functions.datetime.Extract.as_sql
django.db.models.functions.datetime.Extract.lookup_name
django.db.models.functions.datetime.Now.as_mysql
django.db.models.functions.datetime.Now.as_postgresql
django.db.models.functions.datetime.Trunc.__init__
django.db.models.functions.datetime.TruncBase.__init__
django.db.models.functions.datetime.TruncBase.as_sql
django.db.models.functions.datetime.TruncBase.kind
django.db.models.functions.datetime.TruncDate.as_sql
django.db.models.functions.datetime.TruncTime.as_sql
django.db.models.functions.math.Ceil.as_oracle
django.db.models.functions.math.Cot.as_oracle
django.db.models.functions.math.Degrees.as_oracle
Expand Down