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

Update function signatures for django.db.models.sql.Query class #2253

Merged
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
62 changes: 41 additions & 21 deletions django-stubs/db/models/sql/query.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import collections
from collections import namedtuple
from collections.abc import Callable, Iterable, Iterator, Sequence
from collections.abc import Iterable, Iterator, Sequence
from typing import Any, Literal

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.utils import CursorWrapper
from django.db.models import Field, FilteredRelation, Model, Q
from django.db.models.expressions import BaseExpression, Combinable, Expression, OrderBy
from django.db.models.lookups import Lookup, Transform
from django.db.models.options import Options
from django.db.models.query_utils import PathInfo
from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.datastructures import BaseTable, Join
from django.db.models.sql.where import WhereNode
from django.utils.functional import cached_property
Expand Down Expand Up @@ -41,6 +39,7 @@ class Query(BaseExpression):
alias_prefix: str
subq_aliases: frozenset[Any]
compiler: str
base_table_class: type[BaseTable]
model: type[Model] | None
alias_refcount: dict[str, int]
alias_map: dict[str, BaseTable | Join]
Expand All @@ -65,6 +64,7 @@ class Query(BaseExpression):
select_for_no_key_update: bool
select_related: dict[str, Any] | bool
max_depth: int
join_class: type[Join]
values_select: tuple
annotation_select_mask: list[str] | None
combinator: str | None
Expand All @@ -81,51 +81,73 @@ class Query(BaseExpression):
low_mark: int
extra: dict[str, Any]
annotations: dict[str, Expression]
def __init__(self, model: type[Model] | None, where: type[WhereNode] = ..., alias_cols: bool = ...) -> None: ...
empty_result_set_value: Any | None
explain_info: Any | None
def __init__(self, model: type[Model] | None, alias_cols: bool = True) -> None: ...
@property
def output_field(self) -> Field: ...
@property
def has_select_fields(self) -> bool: ...
@cached_property
def base_table(self) -> str: ...
def add_annotation(self, annotation: Any, alias: str, select: bool = True) -> None: ...
def sql_with_params(self) -> tuple[str, tuple]: ...
def __deepcopy__(self, memo: dict[int, Any]) -> Query: ...
def get_compiler(self, using: str | None = ..., connection: BaseDatabaseWrapper | None = ...) -> SQLCompiler: ...
def get_compiler(
self, using: str | None = None, connection: Any | None = None, elide_empty: bool = True
) -> Any: ...
def join_parent_model(self, opts: Any, model: Any | None, alias: str, seen: dict[Any, str]) -> str: ...
def names_to_path(
self, names: list[str], opts: Any, allow_many: bool = True, fail_on_missing: bool = False
) -> tuple[list[Any], Any, tuple[Any, ...], list[str]]: ...
def get_meta(self) -> Options: ...
def clone(self) -> Query: ...
def chain(self, klass: type[Query] | None = ...) -> Query: ...
def get_count(self, using: str) -> int: ...
def get_group_by_cols(self, wrapper: Any | None = None) -> list[Any]: ...
def has_filters(self) -> WhereNode: ...
def get_external_cols(self) -> list[Any]: ...
def exists(self, limit: bool = True) -> Any: ...
def has_results(self, using: str) -> bool: ...
def explain(self, using: str, format: str | None = ..., **options: Any) -> str: ...
def combine(self, rhs: Query, connector: str) -> None: ...
def deferred_to_data(self, target: dict[Any, Any], callback: Callable) -> None: ...
def ref_alias(self, alias: str) -> None: ...
def unref_alias(self, alias: str, amount: int = ...) -> None: ...
def promote_joins(self, aliases: Iterable[str]) -> None: ...
def demote_joins(self, aliases: Iterable[str]) -> None: ...
def reset_refcounts(self, to_counts: dict[str, int]) -> None: ...
def check_alias(self, alias: str) -> None: ...
def check_related_objects(self, field: Any, value: Any, opts: Any) -> None: ...
def check_query_object_type(self, value: Any, opts: Any, field: Any) -> None: ...
def change_aliases(self, change_map: dict[str | None, str]) -> None: ...
def bump_prefix(self, outer_query: Query) -> None: ...
def bump_prefix(self, other_query: Query, exclude: Any | None = None) -> None: ...
def get_initial_alias(self) -> str: ...
def count_active_tables(self) -> int: ...
def resolve_expression(self, query: Query, *args: Any, **kwargs: Any) -> Query: ... # type: ignore[override]
def resolve_lookup_value(
self, value: Any, can_reuse: set[str] | None, allow_joins: bool, summarize: bool = False
) -> Any: ...
def solve_lookup_type(self, lookup: str) -> tuple[Sequence[str], Sequence[str], Expression | Literal[False]]: ...
def solve_lookup_type(
self, lookup: str, summarize: bool = False
) -> tuple[Sequence[str], Sequence[str], Expression | Literal[False]]: ...
def table_alias(
self, table_name: str, create: bool = False, filtered_relation: Any | None = None
) -> tuple[str, bool]: ...
def get_aggregation(self, using: Any, aggregate_exprs: dict[str, Any]) -> dict[str, Any]: ...
def build_filter(
self,
filter_expr: Q | Expression | dict[str, str] | tuple[str, Any],
branch_negated: bool = ...,
current_negated: bool = ...,
can_reuse: set[str] | None = ...,
allow_joins: bool = ...,
split_subq: bool = ...,
check_filterable: bool = ...,
update_join_types: bool = ...,
branch_negated: bool = False,
current_negated: bool = False,
can_reuse: set[str] | None = None,
allow_joins: bool = True,
split_subq: bool = True,
check_filterable: bool = True,
summarize: bool = False,
update_join_types: bool = True,
) -> tuple[WhereNode, Iterable[str]]: ...
def add_filter(self, filter_clause: tuple[str, Any]) -> None: ...
def add_select_col(self, col: Any, name: str) -> None: ...
def add_filter(self, filter_lhs: tuple[str, Any], filter_rhs: tuple[str, Any]) -> None: ...
def add_q(self, q_object: Q) -> None: ...
def build_where(self, filter_expr: Q | Expression | dict[str, str] | tuple[str, Any]) -> WhereNode: ...
def add_filtered_relation(self, filtered_relation: FilteredRelation, alias: str) -> None: ...
Expand Down Expand Up @@ -163,7 +185,8 @@ class Query(BaseExpression):
def add_distinct_fields(self, *field_names: Any) -> None: ...
def add_fields(self, field_names: Iterable[str], allow_m2m: bool = ...) -> None: ...
def add_ordering(self, *ordering: str | OrderBy) -> None: ...
def clear_ordering(self, force_empty: bool) -> None: ...
def clear_where(self) -> None: ...
def clear_ordering(self, force: bool = False, clear_default: bool = True) -> None: ...
def set_group_by(self, allow_aliases: bool = ...) -> None: ...
def add_select_related(self, fields: Iterable[str]) -> None: ...
def add_extra(
Expand All @@ -178,10 +201,7 @@ class Query(BaseExpression):
def clear_deferred_loading(self) -> None: ...
def add_deferred_loading(self, field_names: Iterable[str]) -> None: ...
def add_immediate_loading(self, field_names: Iterable[str]) -> None: ...
def get_loaded_field_names(self) -> dict[type[Model], set[str]]: ...
def get_loaded_field_names_cb(
self, target: dict[type[Model], set[str]], model: type[Model], fields: set[Field]
) -> None: ...
def get_select_mask(self) -> dict[str, Any]: ...
def set_annotation_mask(self, names: Iterable[str] | None) -> None: ...
def append_annotation_mask(self, names: Iterable[str]) -> None: ...
def set_extra_mask(self, names: Iterable[str] | None) -> None: ...
Expand Down
56 changes: 0 additions & 56 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1164,34 +1164,6 @@ django.db.models.sql.AND
django.db.models.sql.AggregateQuery.__init__
django.db.models.sql.InsertQuery.__init__
django.db.models.sql.OR
django.db.models.sql.Query.__init__
django.db.models.sql.Query.add_annotation
django.db.models.sql.Query.add_filter
django.db.models.sql.Query.add_select_col
django.db.models.sql.Query.base_table_class
django.db.models.sql.Query.build_filter
django.db.models.sql.Query.bump_prefix
django.db.models.sql.Query.check_alias
django.db.models.sql.Query.check_query_object_type
django.db.models.sql.Query.check_related_objects
django.db.models.sql.Query.clear_ordering
django.db.models.sql.Query.clear_where
django.db.models.sql.Query.deferred_to_data
django.db.models.sql.Query.empty_result_set_value
django.db.models.sql.Query.exists
django.db.models.sql.Query.explain_info
django.db.models.sql.Query.get_aggregation
django.db.models.sql.Query.get_compiler
django.db.models.sql.Query.get_external_cols
django.db.models.sql.Query.get_group_by_cols
django.db.models.sql.Query.get_loaded_field_names
django.db.models.sql.Query.get_loaded_field_names_cb
django.db.models.sql.Query.get_select_mask
django.db.models.sql.Query.join_class
django.db.models.sql.Query.join_parent_model
django.db.models.sql.Query.names_to_path
django.db.models.sql.Query.solve_lookup_type
django.db.models.sql.Query.table_alias
django.db.models.sql.XOR
django.db.models.sql.compiler.SQLCompiler.__init__
django.db.models.sql.compiler.SQLCompiler.deferred_to_columns
Expand All @@ -1200,34 +1172,6 @@ django.db.models.sql.compiler.SQLCompiler.get_qualify_sql
django.db.models.sql.compiler.SQLCompiler.get_related_selections
django.db.models.sql.datastructures.BaseTable.identity
django.db.models.sql.datastructures.Join.identity
django.db.models.sql.query.Query.__init__
django.db.models.sql.query.Query.add_annotation
django.db.models.sql.query.Query.add_filter
django.db.models.sql.query.Query.add_select_col
django.db.models.sql.query.Query.base_table_class
django.db.models.sql.query.Query.build_filter
django.db.models.sql.query.Query.bump_prefix
django.db.models.sql.query.Query.check_alias
django.db.models.sql.query.Query.check_query_object_type
django.db.models.sql.query.Query.check_related_objects
django.db.models.sql.query.Query.clear_ordering
django.db.models.sql.query.Query.clear_where
django.db.models.sql.query.Query.deferred_to_data
django.db.models.sql.query.Query.empty_result_set_value
django.db.models.sql.query.Query.exists
django.db.models.sql.query.Query.explain_info
django.db.models.sql.query.Query.get_aggregation
django.db.models.sql.query.Query.get_compiler
django.db.models.sql.query.Query.get_external_cols
django.db.models.sql.query.Query.get_group_by_cols
django.db.models.sql.query.Query.get_loaded_field_names
django.db.models.sql.query.Query.get_loaded_field_names_cb
django.db.models.sql.query.Query.get_select_mask
django.db.models.sql.query.Query.join_class
django.db.models.sql.query.Query.join_parent_model
django.db.models.sql.query.Query.names_to_path
django.db.models.sql.query.Query.solve_lookup_type
django.db.models.sql.query.Query.table_alias
django.db.models.sql.subqueries.AggregateQuery.__init__
django.db.models.sql.subqueries.InsertQuery.__init__
django.db.models.sql.where.ExtraWhere.contains_over_clause
Expand Down
Loading