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 4 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
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
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target-version = "py38"
select = [
"I", # isort
"F401", # Unused imports
"UP", # pyupgrade
]

[tool.ruff.isort]
Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck/db/migrations/test_operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

RunSQL(sql=["SOME SQLS", ("SOME SQLS %s, %s", ["PARAM", "ANOTHER PARAM"])], reverse_sql=["SOME SQLS", ("SOME SQLS %s, %s", ["PARAM", "ANOTHER PARAM"])])

RunSQL(sql=("SOME SQL", {})) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, Dict[<nothing>, <nothing>]]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], List[str], Tuple[str, ...], Tuple[], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], List[str], Tuple[str, ...], Tuple[], None]]], ...], Tuple[]]]"
RunSQL(sql=("SOME SQL", {})) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, Dict[<nothing>, <nothing>]]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[str], Tuple[str, ...], Tuple[]], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[str], Tuple[str, ...], Tuple[]], None]]], ...], Tuple[]]]"
RunSQL(sql=["SOME SQLS", ("SOME SQLS %s, %s", [object(), "ANOTHER PARAM"])]) # E: List item 0 has incompatible type "object"; expected "str"