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

Migrate from flake8 to ruff #488

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ repos:
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-pyi==22.11.0
types: []
files: ^.*.pyi?$

ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pre-commit install

### Testing and Linting

We use `mypy`, `pytest`, `flake8`, and `black` for quality control. All tools except pytest are executed using pre-commit when you make a commit.
We use `mypy`, `pytest`, `ruff`, and `black` for quality control. All tools except pytest are executed using pre-commit when you make a commit.
To ensure there are not formatting or typing issues in the entire repository you can run:

```bash
Expand Down
36 changes: 32 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include = '\.pyi?$'
[tool.ruff]
# Adds to default excludes: https://ruff.rs/docs/settings/#exclude
extend-exclude = [
".*/",
"drf_source",
"stubgen",
"out",
Expand All @@ -13,11 +14,38 @@ line-length = 120
target-version = "py38"
# See Rules in Ruff documentation: https://beta.ruff.rs/docs/rules/
select = [
"I", # isort
"F401", # Unused imports
"UP", # pyupgrade
"TID", # flake8-tidy-imports
"B", # bugbear
"E", # pycodestyle
"F", # pyflakes
"INP", # flake8-tidy-imports
"W", # pycodestyle
"I", # isort
"UP", # pyupgrade
"TID251", # Disallowed imports (flake8-tidy-imports.banned-api)
"PYI", # flake8-pyi
"RUF100", # Equivalent to flake8-noqa NQA103
"PGH004", # Equivalent to flake8-noqa NQA104
"PGH003", # Disallowed blanket `type: ignore` annotations.
]
ignore = ["PYI021", "PYI024", "PYI041", "PYI043"]

[tool.ruff.per-file-ignores]
"*.pyi" = [
"B",
"E501",
"E741",
"E743",
"F403", # Use wildcard import
"F405",
"F822",
"F821",
"PYI026", # TODO fix these errors
"PGH003", # TODO fix these errors
"PYI002", # TODO fix these errors
]
#"tests/*.py" = ["INP001"]
#"ext/tests/*.py" = ["INP001"]
#"setup.py" = ["INP001"]
intgr marked this conversation as resolved.
Show resolved Hide resolved

[tool.ruff.flake8-tidy-imports.banned-api]
"_typeshed.Self".msg = "Use typing_extensions.Self (PEP 673) instead."
Expand Down
1 change: 0 additions & 1 deletion rest_framework-stubs/compat.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any

import requests # noqa: F401
from django.db.models import QuerySet

try:
Expand Down
4 changes: 2 additions & 2 deletions rest_framework-stubs/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from rest_framework.validators import Validator
from typing_extensions import Self, TypeAlias

class _Empty(Enum):
sentinel = 0 # noqa: Y015
sentinel = 0

empty: Final = _Empty.sentinel

Expand Down Expand Up @@ -329,7 +329,7 @@ class DecimalField(Field[Decimal, int | float | str | Decimal, str, Any]):
min_value: Decimal | int | float | None
localize: bool
rounding: str | None
max_whole_digits = int | None # noqa: Y026
max_whole_digits: int | None
def __init__(
self,
max_digits: int | None,
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/generics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GenericAPIView(views.APIView, UsesQuerySet[_MT_co]):
serializer_class: type[BaseSerializer] | None
lookup_field: str
lookup_url_kwarg: str | None
filter_backends: Sequence[type[BaseFilterBackend] | type[BaseFilterProtocol[_MT_co]]]
filter_backends: Sequence[type[BaseFilterBackend | BaseFilterProtocol[_MT_co]]]
pagination_class: type[BasePagination] | None
def get_object(self) -> _MT_co: ...
def get_serializer(self, *args: Any, **kwargs: Any) -> BaseSerializer[_MT_co]: ...
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/permissions.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Sequence
from typing import Any, Protocol # noqa: Y037 # https://github.com/python/mypy/issues/12392
from typing import Any, Protocol

from django.db.models import Model, QuerySet
from rest_framework.request import Request
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/serializers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from rest_framework.exceptions import Throttled as Throttled
from rest_framework.exceptions import UnsupportedMediaType as UnsupportedMediaType
from rest_framework.exceptions import ValidationError as ValidationError
from rest_framework.fields import BooleanField as BooleanField
from rest_framework.fields import CharField as CharField # noqa: F401
from rest_framework.fields import CharField as CharField
from rest_framework.fields import ChoiceField as ChoiceField
from rest_framework.fields import CreateOnlyDefault as CreateOnlyDefault
from rest_framework.fields import CurrentUserDefault as CurrentUserDefault
Expand Down