-
-
Notifications
You must be signed in to change notification settings - Fork 452
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 BaseDatabaseOperations
#2238
Open
Viicos
wants to merge
4
commits into
typeddjango:master
Choose a base branch
from
Viicos:patch-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import json | ||
from collections.abc import Iterable, Sequence | ||
from collections.abc import Callable, Sequence | ||
from datetime import date, time, timedelta | ||
from datetime import datetime as real_datetime | ||
from decimal import Decimal | ||
|
@@ -13,13 +13,16 @@ from django.db.models.constants import OnConflict | |
from django.db.models.expressions import Case, Col, Expression | ||
from django.db.models.fields import Field | ||
from django.db.models.sql.compiler import SQLCompiler | ||
from typing_extensions import TypeAlias | ||
|
||
_Converter: TypeAlias = Callable[[Any, Expression, BaseDatabaseWrapper], Any] | ||
|
||
class BaseDatabaseOperations: | ||
compiler_module: str | ||
integer_field_ranges: dict[str, tuple[int, int]] | ||
set_operators: dict[str, str] | ||
cast_data_types: dict[Any, Any] | ||
cast_char_field_without_max_length: Any | ||
cast_char_field_without_max_length: str | None | ||
PRECEDING: str | ||
FOLLOWING: str | ||
UNBOUNDED_PRECEDING: str | ||
|
@@ -57,7 +60,7 @@ class BaseDatabaseOperations: | |
def pk_default_value(self) -> str: ... | ||
def prepare_sql_script(self, sql: Any) -> list[str]: ... | ||
def process_clob(self, value: str) -> str: ... | ||
def return_insert_columns(self, fields: Any) -> Any: ... | ||
def return_insert_columns(self, fields: list[Field[Any, Any]]) -> tuple[str, list[Any]]: ... | ||
def compiler(self, compiler_name: str) -> type[SQLCompiler]: ... | ||
def quote_name(self, name: str) -> str: ... | ||
def regex_lookup(self, lookup_type: str) -> str: ... | ||
|
@@ -66,16 +69,16 @@ class BaseDatabaseOperations: | |
def savepoint_rollback_sql(self, sid: str) -> str: ... | ||
def set_time_zone_sql(self) -> str: ... | ||
def sql_flush( | ||
self, style: Any, tables: Sequence[str], *, reset_sequences: bool = ..., allow_cascade: bool = ... | ||
self, style: Style, tables: Sequence[str], *, reset_sequences: bool = ..., allow_cascade: bool = ... | ||
) -> list[str]: ... | ||
def execute_sql_flush(self, sql_list: Iterable[str]) -> None: ... | ||
def sequence_reset_by_name_sql(self, style: Style | None, sequences: list[Any]) -> list[Any]: ... | ||
def sequence_reset_sql(self, style: Style, model_list: Sequence[type[Model]]) -> list[Any]: ... | ||
def execute_sql_flush(self, sql_list: list[str]) -> None: ... | ||
def sequence_reset_by_name_sql(self, style: Style, sequences: list[dict[str, str | None]]) -> list[str]: ... | ||
def sequence_reset_sql(self, style: Style, model_list: list[type[Model]]) -> list[str]: ... | ||
def start_transaction_sql(self) -> str: ... | ||
def end_transaction_sql(self, success: bool = ...) -> str: ... | ||
def tablespace_sql(self, tablespace: str | None, inline: bool = ...) -> str: ... | ||
def prep_for_like_query(self, x: str) -> str: ... | ||
prep_for_iexact_query: Any | ||
def tablespace_sql(self, tablespace: str, inline: bool = ...) -> str: ... | ||
def prep_for_like_query(self, x: object) -> str: ... | ||
def prep_for_iexact_query(self, x: object) -> str: ... | ||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think |
||
def validate_autopk_value(self, value: int) -> int: ... | ||
def adapt_unknown_value(self, value: Any) -> Any: ... | ||
def adapt_datefield_value(self, value: date | None) -> str | None: ... | ||
|
@@ -89,14 +92,14 @@ class BaseDatabaseOperations: | |
def adapt_integerfield_value(self, value: Any, internal_type: Any) -> Any: ... | ||
def year_lookup_bounds_for_date_field(self, value: int, iso_year: bool = ...) -> list[str]: ... | ||
def year_lookup_bounds_for_datetime_field(self, value: int, iso_year: bool = ...) -> list[str]: ... | ||
def get_db_converters(self, expression: Expression) -> list[Any]: ... | ||
def get_db_converters(self, expression: Expression) -> list[_Converter]: ... | ||
def convert_durationfield_value( | ||
self, value: float | None, expression: Expression, connection: BaseDatabaseWrapper | ||
) -> timedelta | None: ... | ||
def check_expression_support(self, expression: Any) -> None: ... | ||
def conditional_expression_supported_in_where_clause(self, expression: Any) -> bool: ... | ||
def check_expression_support(self, expression: Expression) -> None: ... | ||
def conditional_expression_supported_in_where_clause(self, expression: Expression) -> bool: ... | ||
def combine_expression(self, connector: str, sub_expressions: list[str]) -> str: ... | ||
def combine_duration_expression(self, connector: Any, sub_expressions: Any) -> str: ... | ||
def combine_duration_expression(self, connector: str, sub_expressions: list[str]) -> str: ... | ||
def binary_placeholder_sql(self, value: Case | None) -> str: ... | ||
def modify_insert_params(self, placeholder: str, params: Any) -> Any: ... | ||
def integer_field_range(self, internal_type: Any) -> tuple[int, int]: ... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
sequence_reset_sql
only iterates over themodel_list
, I typing this aslist
seems too strict.Sequence[]
orIterable[]
would be better.Same for
execute_sql_flush
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for
list
as these methods receive an actuallist
at runtime (e.g.sequence_reset_sql
receives the result ofsql_flush
), so I assumed it is safe to allowBaseDatabaseOperations
subclasses to rely on the available attributes/methods oflist
in these methods. On the other hand, keepingSequence
seems fine as well