From 5da475cdcd24faafd10f902d40b15c572c51bb34 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Tue, 6 Jun 2023 11:44:01 +0300 Subject: [PATCH] CI: Auto-remove unused imports using Ruff (#1508) * CI: Remove unused imports using Ruff * Suppress unused import in django-stubs/conf/__init__.pyi --- .pre-commit-config.yaml | 2 +- django-stubs/conf/__init__.pyi | 2 +- django-stubs/contrib/admin/checks.pyi | 2 +- django-stubs/contrib/admin/widgets.pyi | 2 +- django-stubs/contrib/gis/geos/io.pyi | 2 -- django-stubs/contrib/gis/utils/ogrinfo.pyi | 2 -- django-stubs/contrib/messages/storage/__init__.pyi | 2 -- django-stubs/contrib/postgres/lookups.pyi | 4 ++-- django-stubs/contrib/sitemaps/views.pyi | 2 +- django-stubs/contrib/syndication/views.pyi | 1 - django-stubs/core/checks/security/base.pyi | 2 +- django-stubs/core/files/uploadedfile.pyi | 2 +- django-stubs/core/paginator.pyi | 2 -- django-stubs/db/backends/mysql/client.pyi | 2 +- django-stubs/db/migrations/graph.pyi | 2 +- django-stubs/db/models/constraints.pyi | 2 +- django-stubs/db/models/deletion.pyi | 2 +- django-stubs/db/models/expressions.pyi | 2 +- django-stubs/db/models/fields/__init__.pyi | 1 - django-stubs/db/models/fields/related_descriptors.pyi | 3 +-- django-stubs/db/models/signals.pyi | 1 - django-stubs/db/models/sql/query.pyi | 4 ++-- django-stubs/db/models/sql/subqueries.pyi | 1 - django-stubs/forms/fields.pyi | 2 +- django-stubs/template/backends/base.pyi | 1 - django-stubs/template/context.pyi | 2 +- django-stubs/utils/asyncio.pyi | 2 +- django-stubs/utils/text.pyi | 1 - django-stubs/utils/translation/trans_null.pyi | 2 -- django-stubs/views/debug.pyi | 1 - pyproject.toml | 1 + 31 files changed, 21 insertions(+), 38 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 675c974e6..463d1c4bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: rev: v0.0.270 hooks: - id: ruff - args: ["--fix", "--fixable=I001", "--exit-non-zero-on-fix"] + args: ["--fix", "--exit-non-zero-on-fix"] - repo: https://github.com/psf/black rev: 23.3.0 hooks: diff --git a/django-stubs/conf/__init__.pyi b/django-stubs/conf/__init__.pyi index 25dfbc0f7..9651961b8 100644 --- a/django-stubs/conf/__init__.pyi +++ b/django-stubs/conf/__init__.pyi @@ -5,7 +5,7 @@ from django.utils.functional import LazyObject from typing_extensions import Literal # explicit dependency on standard settings to make it loaded -from . import global_settings +from . import global_settings # noqa: F401 ENVIRONMENT_VARIABLE: Literal["DJANGO_SETTINGS_MODULE"] DEFAULT_STORAGE_ALIAS: Literal["default"] diff --git a/django-stubs/contrib/admin/checks.pyi b/django-stubs/contrib/admin/checks.pyi index ecef0ea7f..0921c73cb 100644 --- a/django-stubs/contrib/admin/checks.pyi +++ b/django-stubs/contrib/admin/checks.pyi @@ -3,7 +3,7 @@ from typing import Any from django.apps.config import AppConfig from django.contrib.admin.options import BaseModelAdmin -from django.core.checks.messages import CheckMessage, Error +from django.core.checks.messages import CheckMessage def check_admin_app(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> list[CheckMessage]: ... def check_dependencies(**kwargs: Any) -> list[CheckMessage]: ... diff --git a/django-stubs/contrib/admin/widgets.pyi b/django-stubs/contrib/admin/widgets.pyi index b275244a6..1d08d39aa 100644 --- a/django-stubs/contrib/admin/widgets.pyi +++ b/django-stubs/contrib/admin/widgets.pyi @@ -5,7 +5,7 @@ from django import forms from django.contrib.admin.sites import AdminSite from django.core.files.base import File from django.db.models.fields import _FieldChoices -from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToManyRel, ManyToOneRel +from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel from django.forms.models import ModelChoiceIterator from django.forms.widgets import _OptAttrs from django.utils.functional import _StrOrPromise diff --git a/django-stubs/contrib/gis/geos/io.pyi b/django-stubs/contrib/gis/geos/io.pyi index c061120f2..fb65ab711 100644 --- a/django-stubs/contrib/gis/geos/io.pyi +++ b/django-stubs/contrib/gis/geos/io.pyi @@ -1,5 +1,3 @@ -from typing import Any - from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.prototypes.io import WKBWriter as WKBWriter # noqa: F401 from django.contrib.gis.geos.prototypes.io import WKTWriter as WKTWriter diff --git a/django-stubs/contrib/gis/utils/ogrinfo.pyi b/django-stubs/contrib/gis/utils/ogrinfo.pyi index 18fd4f02f..3028569af 100644 --- a/django-stubs/contrib/gis/utils/ogrinfo.pyi +++ b/django-stubs/contrib/gis/utils/ogrinfo.pyi @@ -1,5 +1,3 @@ -from typing import Any - from django.contrib.gis.gdal import DataSource def ogrinfo(data_source: str | DataSource, num_features: int = ...) -> None: ... diff --git a/django-stubs/contrib/messages/storage/__init__.pyi b/django-stubs/contrib/messages/storage/__init__.pyi index 4c8874558..3616d6f70 100644 --- a/django-stubs/contrib/messages/storage/__init__.pyi +++ b/django-stubs/contrib/messages/storage/__init__.pyi @@ -1,5 +1,3 @@ -from typing import Any - from django.contrib.messages.storage.base import BaseStorage from django.http.request import HttpRequest diff --git a/django-stubs/contrib/postgres/lookups.pyi b/django-stubs/contrib/postgres/lookups.pyi index 247bed981..e18175a09 100644 --- a/django-stubs/contrib/postgres/lookups.pyi +++ b/django-stubs/contrib/postgres/lookups.pyi @@ -1,5 +1,5 @@ -from django.db.models import Lookup, Transform -from django.db.models.lookups import Exact, PostgresOperatorLookup +from django.db.models import Transform +from django.db.models.lookups import PostgresOperatorLookup from .search import SearchVectorExact diff --git a/django-stubs/contrib/sitemaps/views.pyi b/django-stubs/contrib/sitemaps/views.pyi index 9ba674d53..a2f3e92ee 100644 --- a/django-stubs/contrib/sitemaps/views.pyi +++ b/django-stubs/contrib/sitemaps/views.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable from typing import TypeVar -from django.contrib.sitemaps import GenericSitemap, Sitemap +from django.contrib.sitemaps import Sitemap from django.http.request import HttpRequest from django.template.response import TemplateResponse diff --git a/django-stubs/contrib/syndication/views.pyi b/django-stubs/contrib/syndication/views.pyi index daf3bb2a4..f1b03b3b5 100644 --- a/django-stubs/contrib/syndication/views.pyi +++ b/django-stubs/contrib/syndication/views.pyi @@ -1,7 +1,6 @@ from typing import Any, Generic, TypeVar from django.core.exceptions import ObjectDoesNotExist -from django.db.models import Model from django.http.request import HttpRequest from django.http.response import HttpResponse from django.utils.feedgenerator import Enclosure, SyndicationFeed diff --git a/django-stubs/core/checks/security/base.pyi b/django-stubs/core/checks/security/base.pyi index 6db3e735a..f93590ac3 100644 --- a/django-stubs/core/checks/security/base.pyi +++ b/django-stubs/core/checks/security/base.pyi @@ -2,7 +2,7 @@ from collections.abc import Sequence from typing import Any from django.apps.config import AppConfig -from django.core.checks.messages import CheckMessage, Error, Warning +from django.core.checks.messages import Error, Warning CROSS_ORIGIN_OPENER_POLICY_VALUES: set[str] REFERRER_POLICY_VALUES: set[str] diff --git a/django-stubs/core/files/uploadedfile.pyi b/django-stubs/core/files/uploadedfile.pyi index 437da8d9b..23acbba45 100644 --- a/django-stubs/core/files/uploadedfile.pyi +++ b/django-stubs/core/files/uploadedfile.pyi @@ -1,4 +1,4 @@ -from typing import IO, TypeVar +from typing import IO from _typeshed import Self from django.core.files.base import File diff --git a/django-stubs/core/paginator.pyi b/django-stubs/core/paginator.pyi index 147a117e3..692a83c8e 100644 --- a/django-stubs/core/paginator.pyi +++ b/django-stubs/core/paginator.pyi @@ -1,8 +1,6 @@ from collections.abc import Iterable, Iterator, Sequence, Sized from typing import Generic, Protocol, TypeVar, overload -from django.db.models.base import Model -from django.db.models.query import QuerySet from typing_extensions import TypeAlias class UnorderedObjectListWarning(RuntimeWarning): ... diff --git a/django-stubs/db/backends/mysql/client.pyi b/django-stubs/db/backends/mysql/client.pyi index 2bd059811..f3fa6ff30 100644 --- a/django-stubs/db/backends/mysql/client.pyi +++ b/django-stubs/db/backends/mysql/client.pyi @@ -1,4 +1,4 @@ -from collections.abc import Iterable, Sequence +from collections.abc import Iterable from typing import Any from django.db.backends.base.client import BaseDatabaseClient diff --git a/django-stubs/db/migrations/graph.pyi b/django-stubs/db/migrations/graph.pyi index 855038846..f0d8b9a3b 100644 --- a/django-stubs/db/migrations/graph.pyi +++ b/django-stubs/db/migrations/graph.pyi @@ -1,7 +1,7 @@ from collections.abc import Sequence from typing import Any -from django.db.migrations.migration import Migration, SwappableTuple +from django.db.migrations.migration import Migration from django.db.migrations.state import ProjectState RECURSION_DEPTH_WARNING: str diff --git a/django-stubs/db/models/constraints.pyi b/django-stubs/db/models/constraints.pyi index 5c9ffa768..e1e8e8fb7 100644 --- a/django-stubs/db/models/constraints.pyi +++ b/django-stubs/db/models/constraints.pyi @@ -1,6 +1,6 @@ from collections.abc import Sequence from enum import Enum -from typing import Any, TypeVar, overload +from typing import Any, overload from _typeshed import Self from django.db.backends.base.schema import BaseDatabaseSchemaEditor diff --git a/django-stubs/db/models/deletion.pyi b/django-stubs/db/models/deletion.pyi index 8b6a29d26..5fe62c035 100644 --- a/django-stubs/db/models/deletion.pyi +++ b/django-stubs/db/models/deletion.pyi @@ -1,4 +1,4 @@ -from collections.abc import Callable, Collection, Iterable, Iterator, Sequence +from collections.abc import Callable, Iterable, Iterator, Sequence from typing import Any from django.db import IntegrityError diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index f695c39e2..8ebde985c 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -1,7 +1,7 @@ import datetime from collections.abc import Callable, Iterable, Iterator, Sequence from decimal import Decimal -from typing import Any, TypeVar +from typing import Any from _typeshed import Self from django.db.backends.base.base import BaseDatabaseWrapper diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 3e739e94f..35345f690 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -13,7 +13,6 @@ from django.db.models import Model from django.db.models.expressions import Col, Combinable from django.db.models.fields.reverse_related import ForeignObjectRel from django.db.models.query_utils import Q, RegisterLookupMixin -from django.forms import Field as FormField from django.forms import Widget from django.utils.datastructures import DictWrapper from django.utils.functional import _Getter, _StrOrPromise diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 443f76354..644d15c0f 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -4,8 +4,7 @@ from typing import Any, Generic, TypeVar from django.core.exceptions import ObjectDoesNotExist from django.db.models.base import Model from django.db.models.fields import Field -from django.db.models.fields.mixins import FieldCacheMixin -from django.db.models.fields.related import ForeignKey, ManyToManyField, OneToOneField, RelatedField +from django.db.models.fields.related import ForeignKey, RelatedField from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel, OneToOneRel from django.db.models.manager import RelatedManager from django.db.models.query import QuerySet diff --git a/django-stubs/db/models/signals.pyi b/django-stubs/db/models/signals.pyi index 13cb3c252..d856c00e2 100644 --- a/django-stubs/db/models/signals.pyi +++ b/django-stubs/db/models/signals.pyi @@ -1,5 +1,4 @@ from collections.abc import Callable -from typing import Any from django.apps.registry import Apps from django.db.models.base import Model diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index 975c049e5..e5db352ca 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -5,11 +5,11 @@ from typing import Any from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.utils import CursorWrapper -from django.db.models import Field, FilteredRelation, Model, Q, QuerySet +from django.db.models import Field, FilteredRelation, Model, Q from django.db.models.expressions import BaseExpression, Combinable, Expression, OrderBy from django.db.models.lookups import Lookup, Transform from django.db.models.options import Options -from django.db.models.query_utils import PathInfo, RegisterLookupMixin +from django.db.models.query_utils import PathInfo from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.datastructures import BaseTable, Join from django.db.models.sql.where import WhereNode diff --git a/django-stubs/db/models/sql/subqueries.pyi b/django-stubs/db/models/sql/subqueries.pyi index d3c3e024d..ef996eb92 100644 --- a/django-stubs/db/models/sql/subqueries.pyi +++ b/django-stubs/db/models/sql/subqueries.pyi @@ -4,7 +4,6 @@ from typing import Any from django.db.models.base import Model from django.db.models.expressions import Case from django.db.models.fields import Field -from django.db.models.query import QuerySet from django.db.models.sql.query import Query from django.db.models.sql.where import WhereNode diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index 28ae7d0fe..64b9faf39 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -10,7 +10,7 @@ from django.core.validators import _ValidatorCallable from django.db.models.fields import _Choice, _ChoiceNamedGroup, _ChoicesCallable, _ErrorMessagesT, _FieldChoices from django.forms.boundfield import BoundField from django.forms.forms import BaseForm -from django.forms.widgets import ChoiceWidget, Widget +from django.forms.widgets import Widget from django.utils.datastructures import _PropertyDescriptor from django.utils.functional import _StrOrPromise from typing_extensions import TypeAlias diff --git a/django-stubs/template/backends/base.pyi b/django-stubs/template/backends/base.pyi index 83437b387..93c70db6d 100644 --- a/django-stubs/template/backends/base.pyi +++ b/django-stubs/template/backends/base.pyi @@ -2,7 +2,6 @@ from collections.abc import Iterator, Mapping from typing import Any, Protocol from django.http.request import HttpRequest -from django.template import TemplateDoesNotExist from django.template.base import Context from django.utils.safestring import SafeString diff --git a/django-stubs/template/context.pyi b/django-stubs/template/context.pyi index 5b79664c4..87d7fedba 100644 --- a/django-stubs/template/context.pyi +++ b/django-stubs/template/context.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Iterable, Iterator from contextlib import contextmanager from types import TracebackType -from typing import Any, TypeVar +from typing import Any from _typeshed import Self from django.http.request import HttpRequest diff --git a/django-stubs/utils/asyncio.pyi b/django-stubs/utils/asyncio.pyi index ed9f47504..00cedc50f 100644 --- a/django-stubs/utils/asyncio.pyi +++ b/django-stubs/utils/asyncio.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable -from typing import Any, TypeVar, overload +from typing import TypeVar, overload _C = TypeVar("_C", bound=Callable) diff --git a/django-stubs/utils/text.pyi b/django-stubs/utils/text.pyi index 1b5f4c871..bdce2414e 100644 --- a/django-stubs/utils/text.pyi +++ b/django-stubs/utils/text.pyi @@ -5,7 +5,6 @@ from typing import TypeVar, overload from django.db.models.base import Model from django.utils.functional import SimpleLazyObject, _StrOrPromise -from django.utils.safestring import SafeString _StrOrPromiseT = TypeVar("_StrOrPromiseT", bound=_StrOrPromise) diff --git a/django-stubs/utils/translation/trans_null.pyi b/django-stubs/utils/translation/trans_null.pyi index 2eb12c6a1..742fc5022 100644 --- a/django-stubs/utils/translation/trans_null.pyi +++ b/django-stubs/utils/translation/trans_null.pyi @@ -1,5 +1,3 @@ -from typing import Any - from django.http.request import HttpRequest def gettext(message: str) -> str: ... diff --git a/django-stubs/views/debug.pyi b/django-stubs/views/debug.pyi index 8d5d4044b..f24184e20 100644 --- a/django-stubs/views/debug.pyi +++ b/django-stubs/views/debug.pyi @@ -1,5 +1,4 @@ from collections.abc import Callable, ItemsView, Iterator -from importlib.abc import SourceLoader from pathlib import Path from types import TracebackType from typing import Any diff --git a/pyproject.toml b/pyproject.toml index 0162edf54..1e499e4cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ line-length = 120 target-version = "py38" select = [ "I", # isort + "F401", # Unused imports ] [tool.ruff.isort]