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 BaseDatabaseOperations #2238

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Jun 26, 2024

I have made things!

Related issues

@intgr intgr changed the title Fix style argument of BaseDatabaseOperations.sql_flush Improve style argument of BaseDatabaseOperations.sql_flush Jun 26, 2024
Copy link
Collaborator

@intgr intgr left a comment

Choose a reason for hiding this comment

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

Thanks! I found some more related inaccurate stubs too.

image

Possibly these methods could be removed from subclasses, if they have the same signature as the BaseDatabaseOperations base class.

@Viicos Viicos changed the title Improve style argument of BaseDatabaseOperations.sql_flush Improve types of BaseDatabaseOperations Jun 26, 2024
@Viicos
Copy link
Contributor Author

Viicos commented Jun 26, 2024

Made some other improvements to remove some unneeded subclass overrides. There's more work needed here, but I don't want to process everything at once

Copy link
Collaborator

@intgr intgr left a comment

Choose a reason for hiding this comment

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

Thanks! Few suggestions.

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]: ...
Copy link
Collaborator

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 the model_list, I typing this as list seems too strict. Sequence[] or Iterable[] would be better.

Same for execute_sql_flush

Copy link
Contributor Author

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 actual list at runtime (e.g. sequence_reset_sql receives the result of sql_flush), so I assumed it is safe to allow BaseDatabaseOperations subclasses to rely on the available attributes/methods of list in these methods. On the other hand, keeping Sequence seems fine as well

Comment on lines +80 to +81
def prep_for_like_query(self, x: object) -> str: ...
def prep_for_iexact_query(self, x: object) -> str: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I think Any has been preferred over object recently.

@intgr intgr self-assigned this Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants