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

CI: Enable Ruff pyupgrade fixes #1509

Merged
merged 5 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ repos:
- id: debug-statements
- id: check-merge-conflict
- id: end-of-file-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
hooks:
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/conf/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Any
from typing import Any, Literal

from _typeshed import Self
from django.utils.functional import LazyObject
from typing_extensions import Literal

# explicit dependency on standard settings to make it loaded
from . import global_settings # noqa: F401
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/conf/global_settings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ from re import Pattern

# This is defined here as a do-nothing function because we can't import
# django.utils.translation -- that module depends on the settings.
from typing import Any, Protocol
from typing import Any, Literal, Protocol

from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

_Admins: TypeAlias = list[tuple[str, str]]

Expand Down
13 changes: 10 additions & 3 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from typing import Any, Generic, Optional, TypeVar, Union # noqa: Y037 # https://github.com/python/mypy/issues/12211
from typing import ( # noqa: Y037 # https://github.com/python/mypy/issues/12211
Any,
Generic,
Literal,
Optional,
TypeVar,
Union,
)

from django import forms
from django.contrib.admin.filters import FieldListFilter, ListFilter
Expand Down Expand Up @@ -33,7 +40,7 @@ from django.urls.resolvers import URLPattern
from django.utils.datastructures import _ListOrTuple
from django.utils.functional import _StrOrPromise
from django.utils.safestring import SafeString
from typing_extensions import Literal, TypeAlias, TypedDict
from typing_extensions import TypeAlias, TypedDict

IS_POPUP_VAR: str
TO_FIELD_VAR: str
Expand Down Expand Up @@ -81,7 +88,7 @@ class BaseModelAdmin(Generic[_ModelT]):
raw_id_fields: Sequence[str]
fields: _FieldGroups | None
exclude: Sequence[str] | None
fieldsets: Optional[_FieldsetSpec]
fieldsets: Optional[_FieldsetSpec] # noqa: UP007
form: type[forms.ModelForm[_ModelT]]
filter_vertical: Sequence[str]
filter_horizontal: Sequence[str]
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from collections.abc import Callable, Iterable, Sequence
from typing import Any, overload
from typing import Any, Literal, overload
from uuid import UUID

from django.contrib.admin.options import BaseModelAdmin
Expand All @@ -15,7 +15,7 @@ from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
from django.utils.datastructures import _IndexableCollection
from typing_extensions import Literal, TypedDict
from typing_extensions import TypedDict

class FieldIsAForeignKeyColumnName(Exception): ...

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/admin/views/main.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable, Iterable, Sequence
from typing import Any
from typing import Any, Literal

from django.contrib.admin.filters import ListFilter
from django.contrib.admin.options import ModelAdmin, _DisplayT, _ListFilterT
Expand All @@ -9,7 +9,6 @@ from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
from typing_extensions import Literal

ALL_VAR: str
ORDER_VAR: str
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/auth/base_user.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Any, TypeVar, overload
from typing import Any, Literal, TypeVar, overload

from django.db import models
from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.fields import BooleanField
from typing_extensions import Literal

_T = TypeVar("_T", bound=Model)

Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/auth/models.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterable
from typing import Any, TypeVar
from typing import Any, Literal, TypeVar

from django.contrib.auth.base_user import AbstractBaseUser as AbstractBaseUser
from django.contrib.auth.base_user import BaseUserManager as BaseUserManager
Expand All @@ -10,7 +10,7 @@ from django.db.models import QuerySet
from django.db.models.base import Model
from django.db.models.manager import EmptyManager
from django.utils.functional import _StrOrPromise
from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

_AnyUser: TypeAlias = Model | AnonymousUser

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/gis/db/backends/postgis/operations.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Any
from typing import Any, Literal

from django.contrib.gis.db.backends.base.operations import BaseSpatialOperations
from django.contrib.gis.db.backends.utils import SpatialOperator
from django.db.backends.postgresql.operations import DatabaseOperations
from django.db.models import Func
from typing_extensions import Literal

BILATERAL: Literal["bilateral"]

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/gis/gdal/layer.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterator
from typing import Any, AnyStr, overload
from typing import Any, AnyStr, Literal, overload

from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.envelope import Envelope
Expand All @@ -9,7 +9,6 @@ from django.contrib.gis.gdal.geometries import OGRGeometry
from django.contrib.gis.gdal.geomtype import OGRGeomType
from django.contrib.gis.gdal.srs import SpatialReference
from django.contrib.gis.geos.geometry import GEOSGeometry
from typing_extensions import Literal

class Layer(GDALBase):
ptr: Any
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/gis/gdal/raster/band.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, overload
from typing import Any, Literal, overload

from django.contrib.gis.gdal.raster.base import GDALRasterBase
from typing_extensions import Literal

class GDALBand(GDALRasterBase):
source: Any
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/postgres/fields/ranges.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any
from typing import Any, Literal

from django.db import models
from django.db.models.lookups import PostgresOperatorLookup
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange, Range
from typing_extensions import Literal

class RangeBoundary(models.Expression):
lower: str
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/contrib/postgres/operations.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Literal

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations import AddConstraint, AddIndex, RemoveIndex
from django.db.migrations.operations.base import Operation
from typing_extensions import Literal

class CreateExtension(Operation):
reversible: bool
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/staticfiles/finders.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from collections.abc import Iterable, Iterator, Sequence
from typing import Any, overload
from typing import Any, Literal, overload

from django.core.checks.messages import CheckMessage
from django.core.files.storage import FileSystemStorage, Storage
from typing_extensions import Literal

searched_locations: Any

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/core/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from collections.abc import Iterator
from typing import Any
from typing import Any, Literal

from django.utils.functional import _StrOrPromise
from typing_extensions import Literal

class FieldDoesNotExist(Exception): ...
class AppRegistryNotReady(Exception): ...
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/core/management/base.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from argparse import ArgumentParser, HelpFormatter, Namespace
from collections.abc import Callable, Iterable, Sequence
from io import TextIOBase
from typing import Any, TextIO
from typing import Any, Literal, TextIO

from django.apps.config import AppConfig
from django.core.management.color import Style
from django.utils.datastructures import _ListOrTuple
from typing_extensions import Literal

class CommandError(Exception):
def __init__(self, *args: Any, returncode: int = ..., **kwargs: Any) -> None: ...
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/backends/mysql/base.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from collections.abc import Container, Iterator
from typing import Any
from typing import Any, Literal

from django.db.backends.base.base import BaseDatabaseWrapper
from typing_extensions import Literal

from .client import DatabaseClient
from .creation import DatabaseCreation
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/backends/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ from contextlib import contextmanager
from decimal import Decimal
from logging import Logger
from types import TracebackType
from typing import Any, Protocol, overload
from typing import Any, Literal, Protocol, overload
from uuid import UUID

from _typeshed import Self
from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

logger: Logger

Expand Down
11 changes: 5 additions & 6 deletions django-stubs/db/migrations/operations/special.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections.abc import Mapping, Sequence
from typing import Any, Optional, Protocol # noqa: Y037 # https://github.com/python/mypy/issues/12211
from typing import Any, Literal, Protocol

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.utils.datastructures import _ListOrTuple
from typing_extensions import Literal

from .base import Operation

Expand All @@ -17,14 +16,14 @@ class SeparateDatabaseAndState(Operation):

class RunSQL(Operation):
noop: Literal[""]
sql: str | _ListOrTuple[str | tuple[str, dict[str, Any] | Optional[_ListOrTuple[str]]]]
reverse_sql: str | None | _ListOrTuple[str | tuple[str, dict[str, Any] | Optional[_ListOrTuple[str]]]]
sql: str | _ListOrTuple[str | tuple[str, dict[str, Any] | _ListOrTuple[str] | None]]
reverse_sql: str | None | _ListOrTuple[str | tuple[str, dict[str, Any] | _ListOrTuple[str] | None]]
state_operations: Sequence[Operation]
hints: Mapping[str, Any]
def __init__(
self,
sql: str | _ListOrTuple[str | tuple[str, dict[str, Any] | Optional[_ListOrTuple[str]]]],
reverse_sql: str | None | _ListOrTuple[str | tuple[str, dict[str, Any] | Optional[_ListOrTuple[str]]]] = ...,
sql: str | _ListOrTuple[str | tuple[str, dict[str, Any] | _ListOrTuple[str] | None]],
reverse_sql: str | None | _ListOrTuple[str | tuple[str, dict[str, Any] | _ListOrTuple[str] | None]] = ...,
state_operations: Sequence[Operation] = ...,
hints: Mapping[str, Any] | None = ...,
elidable: bool = ...,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/migrations/operations/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from collections import namedtuple
from collections.abc import Iterator
from typing import Literal

from django.db.migrations.state import ModelState, ProjectState
from django.db.models import Field, Model
from typing_extensions import Literal

def resolve_relation(
model: str | type[Model], app_label: str | None = ..., model_name: str | None = ...
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/models/base.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Collection, Iterable, Sequence
from typing import Any, TypeVar
from typing import Any, Final, TypeVar

from _typeshed import Self
from django.core.checks.messages import CheckMessage
Expand All @@ -8,7 +8,6 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db.models import BaseConstraint, Field
from django.db.models.manager import BaseManager
from django.db.models.options import Options
from typing_extensions import Final

_Self = TypeVar("_Self", bound=Model)

Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/expressions.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from collections.abc import Callable, Iterable, Iterator, Sequence
from decimal import Decimal
from typing import Any
from typing import Any, Literal

from _typeshed import Self
from django.db.backends.base.base import BaseDatabaseWrapper
Expand All @@ -11,7 +11,7 @@ from django.db.models.lookups import Lookup, Transform
from django.db.models.query import QuerySet
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from django.db.models.sql.query import Query
from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

class SQLiteNumericMixin:
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/fields/related.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable, Iterable, Sequence
from typing import Any, TypeVar, overload
from typing import Any, Literal, TypeVar, overload
from uuid import UUID

from django.core import validators # due to weird mypy.stubtest error
Expand All @@ -21,7 +21,7 @@ from django.db.models.fields.reverse_related import OneToOneRel as OneToOneRel
from django.db.models.manager import RelatedManager
from django.db.models.query_utils import FilteredRelation, PathInfo, Q
from django.utils.functional import _StrOrPromise
from typing_extensions import Literal, Self
from typing_extensions import Self

RECURSIVE_RELATIONSHIP_CONSTANT: Literal["self"]

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/models/fields/reverse_related.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from collections.abc import Callable, Sequence
from typing import Any
from typing import Any, Literal

from django.db.models.base import Model
from django.db.models.fields import AutoField, Field, _AllLimitChoicesTo, _ChoicesList, _LimitChoicesTo
from django.db.models.fields.related import ForeignKey, ForeignObject, ManyToManyField, OneToOneField
from django.db.models.lookups import Lookup, StartsWith
from django.db.models.query_utils import FilteredRelation, PathInfo
from django.db.models.sql.where import WhereNode
from typing_extensions import Literal

from .mixins import FieldCacheMixin

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/models/lookups.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from collections.abc import Iterable, Mapping
from typing import Any, Generic, TypeVar
from typing import Any, Generic, Literal, TypeVar

from _typeshed import Self
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.expressions import Expression, Func
from django.db.models.query_utils import RegisterLookupMixin
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType, _ParamT
from django.utils.datastructures import OrderedSet
from typing_extensions import Literal

_T = TypeVar("_T")

Expand Down
11 changes: 9 additions & 2 deletions django-stubs/db/models/options.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from collections.abc import Iterable, Sequence
from typing import Any, Generic, TypeVar, Union, overload # noqa: Y037 # https://github.com/python/mypy/issues/12211
from typing import ( # noqa: Y037 # https://github.com/python/mypy/issues/12211
Any,
Generic,
Literal,
TypeVar,
Union,
overload,
)

from django.apps.config import AppConfig
from django.apps.registry import Apps
Expand All @@ -14,7 +21,7 @@ from django.db.models.manager import Manager
from django.db.models.query_utils import PathInfo
from django.utils.datastructures import ImmutableList, _ListOrTuple
from django.utils.functional import _StrOrPromise
from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

PROXY_PARENTS: object
EMPTY_RELATION_TREE: Any
Expand Down
Loading