-
-
Notifications
You must be signed in to change notification settings - Fork 557
typing: improve CaptureQueriesContext and test decorators in django.t… #3233
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,17 +12,15 @@ from django.conf import LazySettings, Settings | |
| from django.core.checks.registry import CheckRegistry | ||
| from django.db.backends.base.base import BaseDatabaseWrapper | ||
| from django.db.models.lookups import Lookup, Transform | ||
| from django.db.models.query import _SupportsContains | ||
| from django.db.models.query_utils import RegisterLookupMixin | ||
| from django.test.runner import DiscoverRunner | ||
| from django.test.testcases import SimpleTestCase | ||
| from typing_extensions import Self, TypeVar, override | ||
|
|
||
| _TestClass: TypeAlias = type[SimpleTestCase] | ||
|
|
||
| _DecoratedTest: TypeAlias = Callable | _TestClass | ||
| _DecoratedTest: TypeAlias = Callable[..., Any] | _TestClass | ||
| _DT = TypeVar("_DT", bound=_DecoratedTest) | ||
| _C = TypeVar("_C", bound=Callable) # Any callable | ||
| _C = TypeVar("_C", bound=Callable[..., Any]) # Any callable | ||
|
|
||
| TZ_SUPPORT: bool | ||
|
|
||
|
|
@@ -81,13 +79,16 @@ class modify_settings(override_settings): | |
|
|
||
| class override_system_checks(TestContextDecorator): | ||
| registry: CheckRegistry | ||
| new_checks: list[Callable] | ||
| deployment_checks: list[Callable] | None | ||
| def __init__(self, new_checks: list[Callable], deployment_checks: list[Callable] | None = ...) -> None: ... | ||
| old_checks: set[Callable] | ||
| old_deployment_checks: set[Callable] | ||
| new_checks: list[Callable[..., Any]] | ||
| deployment_checks: list[Callable[..., Any]] | None | ||
| def __init__( | ||
| self, new_checks: list[Callable[..., Any]], deployment_checks: list[Callable[..., Any]] | None = ... | ||
| ) -> None: ... | ||
| old_checks: set[Callable[..., Any]] | ||
| old_deployment_checks: set[Callable[..., Any]] | ||
|
|
||
| class CaptureQueriesContext(_SupportsContains[dict[str, str]]): | ||
| # Private API removed, iterable-based | ||
| class CaptureQueriesContext(Iterable[dict[str, str]]): | ||
|
Contributor
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.
Is it correct tho? Can you verify at runtime that it really respect the Iterable protocol and adda test in tests/assert_type to demonstrate why this is needed ?
Author
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. Thank you for the review and questions!
Contributor
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.
You did not add a test, pls don’t resolve a thread if you have not addressed the feedback |
||
| connection: BaseDatabaseWrapper | ||
| force_debug_cursor: bool | ||
| initial_queries: int | ||
|
|
@@ -108,13 +109,13 @@ class CaptureQueriesContext(_SupportsContains[dict[str, str]]): | |
|
|
||
| class ignore_warnings(TestContextDecorator): | ||
| ignore_kwargs: dict[str, Any] | ||
| filter_func: Callable | ||
| filter_func: Callable[..., Any] | ||
| def __init__(self, **kwargs: Any) -> None: ... | ||
| catch_warnings: AbstractContextManager[list | None] | ||
|
|
||
| requires_tz_support: Any | ||
|
|
||
| def isolate_lru_cache(lru_cache_object: Callable) -> AbstractContextManager[None]: ... | ||
| def isolate_lru_cache(lru_cache_object: Callable[..., Any]) -> AbstractContextManager[None]: ... | ||
|
|
||
| class override_script_prefix(TestContextDecorator): | ||
| prefix: str | ||
|
|
||
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.
There is no typing improvement, these are equivalent. But it’s slightly better because it would pass mypy no_any_generic check.
However, can we have a more narrow type here or is this the only option?
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.
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.
Can you link to relevant django source code that make you conclude that ?