From a0f88f48e20be370f9e83b647d4ceb2834a254c3 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 22 Jul 2024 20:36:58 +0300 Subject: [PATCH 1/5] Update mypy to 1.11.0 --- README.md | 1 + django-stubs/contrib/admin/utils.pyi | 2 +- django-stubs/db/models/sql/compiler.pyi | 4 ++-- django-stubs/forms/models.pyi | 2 +- django-stubs/utils/encoding.pyi | 2 +- django-stubs/utils/formats.pyi | 4 ++-- requirements.txt | 2 +- setup.py | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d3875a26..8b122aa91 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ We rely on different `django` and `mypy` versions: | django-stubs | Mypy version | Django version | Django partial support | Python version | |----------------|--------------|----------------|------------------------|----------------| +| 5.0.3 | 1.11.x | 5.0 | 4.2 | 3.8 - 3.12 | | 5.0.2 | 1.10.x | 5.0 | 4.2 | 3.8 - 3.12 | | 5.0.1 | 1.10.x | 5.0 | 4.2 | 3.8 - 3.12 | | 5.0.0 | 1.10.x | 5.0 | 4.2, 4.1 | 3.8 - 3.12 | diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index 521f8a9da..811f86f28 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -75,7 +75,7 @@ def lookup_field( name: Callable | str, obj: Model, model_admin: BaseModelAdmin | None = ... ) -> tuple[Field | None, str | None, Any]: ... @overload -def label_for_field( # type: ignore[overload-overlap] +def label_for_field( name: Callable | str, model: type[Model], model_admin: BaseModelAdmin | None = ..., diff --git a/django-stubs/db/models/sql/compiler.pyi b/django-stubs/db/models/sql/compiler.pyi index b000631be..0f9095029 100644 --- a/django-stubs/db/models/sql/compiler.pyi +++ b/django-stubs/db/models/sql/compiler.pyi @@ -98,7 +98,7 @@ class SQLCompiler: ) -> Iterator[Sequence[Any]]: ... def has_results(self) -> bool: ... @overload - def execute_sql( # type: ignore[overload-overlap] + def execute_sql( self, result_type: Literal["cursor"] = ..., chunked_fetch: bool = ..., chunk_size: int = ... ) -> CursorWrapper: ... @overload @@ -106,7 +106,7 @@ class SQLCompiler: self, result_type: Literal["no results"] | None = ..., chunked_fetch: bool = ..., chunk_size: int = ... ) -> None: ... @overload - def execute_sql( # type: ignore[overload-overlap] + def execute_sql( self, result_type: Literal["single"] = ..., chunked_fetch: bool = ..., chunk_size: int = ... ) -> Iterable[Sequence[Any]] | None: ... @overload diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index fab91bc9a..2e5b036d4 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -306,7 +306,7 @@ class ModelMultipleChoiceField(ModelChoiceField[_M]): def modelform_defines_fields(form_class: type[ModelForm]) -> bool: ... @overload -def _get_foreign_key( # type: ignore[overload-overlap] +def _get_foreign_key( parent_model: type[Model], model: type[Model], fk_name: str | None = ..., can_fail: Literal[True] = ... ) -> ForeignKey | None: ... @overload diff --git a/django-stubs/utils/encoding.pyi b/django-stubs/utils/encoding.pyi index c8df836d7..f8bd12113 100644 --- a/django-stubs/utils/encoding.pyi +++ b/django-stubs/utils/encoding.pyi @@ -60,7 +60,7 @@ def iri_to_uri(iri: None) -> None: ... @overload def iri_to_uri(iri: str | Promise) -> str: ... @overload -def uri_to_iri(uri: None) -> None: ... # type: ignore[overload-overlap] +def uri_to_iri(uri: None) -> None: ... @overload def uri_to_iri(uri: Any) -> str: ... def escape_uri_path(path: str) -> str: ... diff --git a/django-stubs/utils/formats.pyi b/django-stubs/utils/formats.pyi index e2182a19b..8aeb0b5e5 100644 --- a/django-stubs/utils/formats.pyi +++ b/django-stubs/utils/formats.pyi @@ -30,13 +30,13 @@ _T = TypeVar("_T") # details it works as expected (all values from Union are `localize`d to str, # while type of others is preserved) @overload -def localize( # type: ignore[overload-overlap] +def localize( value: builtin_datetime | date | time | Decimal | float | str, use_l10n: bool | None = ... ) -> str: ... @overload def localize(value: _T, use_l10n: bool | None = ...) -> _T: ... @overload -def localize_input( # type: ignore[overload-overlap] +def localize_input( value: builtin_datetime | date | time | Decimal | float | str, default: str | None = ... ) -> str: ... @overload diff --git a/requirements.txt b/requirements.txt index 1be44b4c3..6c095e4f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,5 +14,5 @@ Django==5.0.7; python_version >= '3.10' -e .[redis,compatible-mypy,oracle] # Overrides: -mypy==1.10.1 +mypy==1.11.0 pyright==1.1.372 diff --git a/setup.py b/setup.py index 845bf0b63..66043d480 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def find_stub_files(name: str) -> List[str]: # Keep compatible-mypy major.minor version pinned to what we use in CI (requirements.txt) extras_require = { - "compatible-mypy": ["mypy~=1.10.0"], + "compatible-mypy": ["mypy~=1.11.0"], "redis": ["redis"], "oracle": ["oracledb"], } From 7bbfe7655e7cb81e24b5c46a4f755ec3f0405c66 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:37:30 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- django-stubs/db/models/sql/compiler.pyi | 2 +- django-stubs/forms/models.pyi | 2 +- django-stubs/utils/formats.pyi | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/django-stubs/db/models/sql/compiler.pyi b/django-stubs/db/models/sql/compiler.pyi index 0f9095029..16ace84fb 100644 --- a/django-stubs/db/models/sql/compiler.pyi +++ b/django-stubs/db/models/sql/compiler.pyi @@ -98,7 +98,7 @@ class SQLCompiler: ) -> Iterator[Sequence[Any]]: ... def has_results(self) -> bool: ... @overload - def execute_sql( + def execute_sql( self, result_type: Literal["cursor"] = ..., chunked_fetch: bool = ..., chunk_size: int = ... ) -> CursorWrapper: ... @overload diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 2e5b036d4..5e41fc930 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -306,7 +306,7 @@ class ModelMultipleChoiceField(ModelChoiceField[_M]): def modelform_defines_fields(form_class: type[ModelForm]) -> bool: ... @overload -def _get_foreign_key( +def _get_foreign_key( parent_model: type[Model], model: type[Model], fk_name: str | None = ..., can_fail: Literal[True] = ... ) -> ForeignKey | None: ... @overload diff --git a/django-stubs/utils/formats.pyi b/django-stubs/utils/formats.pyi index 8aeb0b5e5..784ad967c 100644 --- a/django-stubs/utils/formats.pyi +++ b/django-stubs/utils/formats.pyi @@ -30,15 +30,11 @@ _T = TypeVar("_T") # details it works as expected (all values from Union are `localize`d to str, # while type of others is preserved) @overload -def localize( - value: builtin_datetime | date | time | Decimal | float | str, use_l10n: bool | None = ... -) -> str: ... +def localize(value: builtin_datetime | date | time | Decimal | float | str, use_l10n: bool | None = ...) -> str: ... @overload def localize(value: _T, use_l10n: bool | None = ...) -> _T: ... @overload -def localize_input( - value: builtin_datetime | date | time | Decimal | float | str, default: str | None = ... -) -> str: ... +def localize_input(value: builtin_datetime | date | time | Decimal | float | str, default: str | None = ...) -> str: ... @overload def localize_input(value: _T, default: str | None = ...) -> _T: ... def sanitize_separators(value: _T) -> _T: ... From 9aadaaeb6bb9aeb20fc17640806abf30be4f19b9 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 22 Jul 2024 20:50:44 +0300 Subject: [PATCH 3/5] Fix CI --- .github/workflows/test.yml | 6 +++++- tests/typecheck/contrib/admin/test_decorators.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4ea7d82e5..5846230c5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,7 +68,11 @@ jobs: # Must match `shard` definition in the test matrix: - name: Run pytest tests - run: PYTHONPATH='.' pytest --num-shards=4 --shard-id=${{ matrix.shard }} tests + run: | + PYTHONPATH='.' pytest + --num-shards=4 --shard-id=${{ matrix.shard }} + --mypy-only-local-stub + tests - name: Run mypy on the test cases run: mypy tests/assert_type diff --git a/tests/typecheck/contrib/admin/test_decorators.yml b/tests/typecheck/contrib/admin/test_decorators.yml index e43f4a993..405695507 100644 --- a/tests/typecheck/contrib/admin/test_decorators.yml +++ b/tests/typecheck/contrib/admin/test_decorators.yml @@ -17,7 +17,7 @@ @admin.display def display_property(self) -> str: ... - @admin.display # E: Decorators on top of @property are not supported [misc] + @admin.display # E: Decorators on top of @property are not supported [prop-decorator] @property def incorrect_property(self) -> str: ... From b27bcfe967cf5964d749c7980549c4d74998e6f8 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 22 Jul 2024 21:05:26 +0300 Subject: [PATCH 4/5] Fix CI --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5846230c5..31b8c36b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -69,9 +69,9 @@ jobs: # Must match `shard` definition in the test matrix: - name: Run pytest tests run: | - PYTHONPATH='.' pytest - --num-shards=4 --shard-id=${{ matrix.shard }} - --mypy-only-local-stub + PYTHONPATH='.' pytest \ + --num-shards=4 --shard-id=${{ matrix.shard }} \ + --mypy-only-local-stub \ tests - name: Run mypy on the test cases run: mypy tests/assert_type From d9f24a64318f0aabfb0277509f6a1fefc0014116 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 22 Jul 2024 21:21:29 +0300 Subject: [PATCH 5/5] Fix CI --- .github/workflows/test.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31b8c36b3..4ea7d82e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,11 +68,7 @@ jobs: # Must match `shard` definition in the test matrix: - name: Run pytest tests - run: | - PYTHONPATH='.' pytest \ - --num-shards=4 --shard-id=${{ matrix.shard }} \ - --mypy-only-local-stub \ - tests + run: PYTHONPATH='.' pytest --num-shards=4 --shard-id=${{ matrix.shard }} tests - name: Run mypy on the test cases run: mypy tests/assert_type