diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9db3cd4a..e1da65f3c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: rev: v3.3.1 hooks: - id: pyupgrade - args: ["--py37-plus"] + args: ["--py38-plus"] - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: diff --git a/README.md b/README.md index d48b4faf3..17916d646 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,6 @@ This happens because these Django classes do not support [`__class_getitem__`](h django_stubs_ext.monkeypatch() ``` - Note: This monkey patching approach will only work when using Python 3.7 and higher, when the `__class_getitem__` magic method was introduced. - You can add extra types to patch with `django_stubs_ext.monkeypatch(extra_classes=[YourDesiredType])` 2. You can use strings instead: `'QuerySet[MyModel]'` and `'Manager[MyModel]'`, this way it will work as a type for `mypy` and as a regular `str` in runtime. diff --git a/django-stubs/core/mail/message.pyi b/django-stubs/core/mail/message.pyi index 23b95fa15..fe79bd3aa 100644 --- a/django-stubs/core/mail/message.pyi +++ b/django-stubs/core/mail/message.pyi @@ -6,10 +6,7 @@ from email.mime.base import MIMEBase from email.mime.message import MIMEMessage from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText - -# switch to tuple once https://github.com/python/mypy/issues/11098 is fixed -# remove Optional once python 3.7 is dropped (Tuple[str | None, ...] works with mypy on py3.10) -from typing import Any, Optional, Tuple, overload # noqa: Y022, Y037 +from typing import Any, overload from django.utils.functional import _StrOrPromise from typing_extensions import TypeAlias @@ -66,12 +63,8 @@ class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): # type: ignore def __setitem__(self, name: str, val: str) -> None: ... _AttachmentContent: TypeAlias = bytes | EmailMessage | Message | SafeMIMEText | str -# switch to tuple once https://github.com/python/mypy/issues/11098 is fixed -# remove Optional once python 3.7 is dropped (Tuple[str | None, ...] works with mypy on py3.10) _AttachmentTuple: TypeAlias = ( - Tuple[str, _AttachmentContent] - | Tuple[Optional[str], _AttachmentContent, str] - | Tuple[str, _AttachmentContent, None] + tuple[str, _AttachmentContent] | tuple[str | None, _AttachmentContent, str] | tuple[str, _AttachmentContent, None] ) class EmailMessage: diff --git a/django_stubs_ext/django_stubs_ext/db/models.py b/django_stubs_ext/django_stubs_ext/db/models.py index 1efeae7af..172cd3055 100644 --- a/django_stubs_ext/django_stubs_ext/db/models.py +++ b/django_stubs_ext/django_stubs_ext/db/models.py @@ -1,10 +1,9 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import ClassVar, List, Sequence, Tuple, Union + from typing import ClassVar, List, Literal, Sequence, Tuple, Union from django.db.models import BaseConstraint, Index - from typing_extensions import Literal from django_stubs_ext import StrOrPromise diff --git a/django_stubs_ext/django_stubs_ext/types.py b/django_stubs_ext/django_stubs_ext/types.py index da321a46d..8c60066c9 100644 --- a/django_stubs_ext/django_stubs_ext/types.py +++ b/django_stubs_ext/django_stubs_ext/types.py @@ -1,6 +1,4 @@ -from typing import Any - -from typing_extensions import Protocol +from typing import Any, Protocol # Used internally by mypy_django_plugin. diff --git a/django_stubs_ext/setup.py b/django_stubs_ext/setup.py index bdf5b4aff..ec5ed6e6b 100755 --- a/django_stubs_ext/setup.py +++ b/django_stubs_ext/setup.py @@ -27,14 +27,13 @@ maintainer="Marti Raudsepp", maintainer_email="marti@juffo.org", py_modules=[], - python_requires=">=3.7", + python_requires=">=3.8", install_requires=dependencies, packages=["django_stubs_ext", *find_packages(exclude=["scripts"])], package_data={"django_stubs_ext": ["py.typed"]}, classifiers=[ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/django_stubs_ext/tests/test_monkeypatching.py b/django_stubs_ext/tests/test_monkeypatching.py index 3eb1c59d8..2ba12ecf9 100644 --- a/django_stubs_ext/tests/test_monkeypatching.py +++ b/django_stubs_ext/tests/test_monkeypatching.py @@ -1,13 +1,12 @@ import builtins from contextlib import suppress -from typing import Iterable, List, Optional +from typing import Iterable, List, Optional, Protocol import pytest from _pytest.fixtures import FixtureRequest from _pytest.monkeypatch import MonkeyPatch from django.db.models import Model from django.forms.models import ModelForm -from typing_extensions import Protocol import django_stubs_ext from django_stubs_ext import patch diff --git a/mypy_django_plugin/django/context.py b/mypy_django_plugin/django/context.py index 2ddddd9c1..1cd5eb700 100644 --- a/mypy_django_plugin/django/context.py +++ b/mypy_django_plugin/django/context.py @@ -2,7 +2,7 @@ import sys from collections import defaultdict from contextlib import contextmanager -from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, Optional, Sequence, Set, Tuple, Type, Union +from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, Literal, Optional, Sequence, Set, Tuple, Type, Union from django.core.exceptions import FieldDoesNotExist, FieldError from django.db import models @@ -20,7 +20,6 @@ from mypy.types import AnyType, Instance from mypy.types import Type as MypyType from mypy.types import TypeOfAny, UnionType -from typing_extensions import Literal from mypy_django_plugin.lib import fullnames, helpers from mypy_django_plugin.lib.fullnames import WITH_ANNOTATIONS_FULLNAME diff --git a/mypy_django_plugin/transformers/managers.py b/mypy_django_plugin/transformers/managers.py index 19e176a25..eeca04751 100644 --- a/mypy_django_plugin/transformers/managers.py +++ b/mypy_django_plugin/transformers/managers.py @@ -1,4 +1,4 @@ -from typing import Optional, Union +from typing import Final, Optional, Union from mypy.checker import TypeChecker from mypy.nodes import ( @@ -22,7 +22,6 @@ from mypy.types import Type as MypyType from mypy.types import TypeOfAny from mypy.typevars import fill_typevars -from typing_extensions import Final from mypy_django_plugin.lib import fullnames, helpers diff --git a/setup.py b/setup.py index cc7ec4eba..fac25ea33 100755 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ def find_stub_files(name: str) -> List[str]: maintainer="Marti Raudsepp", maintainer_email="marti@juffo.org", py_modules=[], - python_requires=">=3.7", + python_requires=">=3.8", install_requires=dependencies, extras_require=extras_require, packages=["django-stubs", *find_packages(exclude=["scripts"])], @@ -60,7 +60,6 @@ def find_stub_files(name: str) -> List[str]: classifiers=[ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10",