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 to Ruff #2367

Merged
merged 8 commits into from
Dec 1, 2022
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
19 changes: 0 additions & 19 deletions .flake8

This file was deleted.

29 changes: 5 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
repos:
- repo: https://github.com/PyCQA/autoflake
rev: 'v1.7.7'
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--ignore-init-module-imports']
name: autoflake
entry: autoflake
language: python
'types': [python]
require_serial: true
exclude: ^tests/codegen/snapshots/python/

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.2.3
hooks:
- id: pyupgrade
args: [--py37-plus, --keep-runtime-typing]

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: ["flake8-eradicate==1.3.0"]
exclude: ^tests/codegen/snapshots/python/

- repo: https://github.com/pycqa/isort
rev: 5.10.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.149
hooks:
- id: isort
- id: ruff
exclude: ^tests/codegen/snapshots/python/

- repo: https://github.com/patrick91/pre-commit-alex
Expand All @@ -43,7 +24,7 @@ repos:
files: '^docs/.*\.mdx?$'

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
Expand Down
65 changes: 52 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include = ["strawberry/py.typed"]
[tool.poetry.urls]
"Discord" = "https://discord.com/invite/3uQ2PaY"
"Twitter" = "https://twitter.com/strawberry_gql"
"Mastodon" = "https://farbun.social/@strawberry"
"Sponsor on GitHub" = "https://github.com/sponsors/strawberry-graphql"
"Sponsor on Open Collective" = "https://opencollective.com/strawberry-graphql"

Expand Down Expand Up @@ -129,19 +130,6 @@ extend-exclude = '''
tests/codegen/snapshots/
'''

[tool.isort]
src_paths = ["strawberry", "tests", "scripts"]
profile = "black"
indent = 4
combine_star = true
combine_as_imports = true
lines_after_imports = 2
known_django = ["django"]
known_graphql = ["graphql"]
known_pytest = ["pytest"]
known_first_party = ["strawberry"]
sections = ["FUTURE", "STDLIB", "PYTEST", "THIRDPARTY", "DJANGO", "GRAPHQL", "FIRSTPARTY", "LOCALFOLDER"]

[tool.pytest.ini_options]
addopts = "-s --emoji --mypy-ini-file=mypy.ini --benchmark-disable"
DJANGO_SETTINGS_MODULE = "tests.django.django_settings"
Expand All @@ -166,3 +154,54 @@ reportMissingImports = true
reportMissingTypeStubs = false
pythonVersion = "3.7"
stubPath = ""

[tool.ruff]
line-length = 88
select = ["E", "F", "ERA", "I"]
ignore = ["I252"]
fix = true
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"tests/codegen/snapshots"
]
src = ["strawberry", "tests"]

[tool.ruff.per-file-ignores]
"tests/federation/printer/*" = ["E501"]
"tests/test_printer/test_basic.py" = ["E501"]
"tests/pyright/test_federation.py" = ["E501"]
"tests/test_printer/test_schema_directives.py" = ["E501"]
# temporary until https://github.com/charliermarsh/ruff/issues/960 is fixed
"tests/federation/printer/test_entities.py" = ["F821"]
"tests/federation/printer/test_keys.py" = ["F821"]
"tests/federation/printer/test_provides.py" = ["F821"]
"tests/schema/test_resolvers.py" = ["F821"]
"tests/test_forward_references.py" = ["F821"]
"tests/types/resolving/test_string_annotations.py" = ["F821"]
"tests/types/test_argument_types.py" = ["F821"]
"tests/types/test_object_types.py" = ["F821"]
"tests/types/test_resolver_types.py" = ["F821"]
"tests/federation/printer/test_requires.py" = ["F821"]

[tool.ruff.isort]
known-first-party = ["strawberry"]
known-third-party = ["django", "graphql"]
extra-standard-library = ["typing_extensions"]
1 change: 0 additions & 1 deletion strawberry/aiohttp/handlers/http_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from io import BytesIO
from typing import Any, Dict, Union

from typing_extensions import Literal

from aiohttp import web
Expand Down
4 changes: 2 additions & 2 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Union,
_eval_type,
)

from typing_extensions import Annotated, Self, get_args, get_origin

from strawberry.exceptions import StrawberryException
Expand Down Expand Up @@ -319,7 +318,8 @@ def _is_union(cls, annotation: Any) -> bool:
if isinstance(annotation, UnionType):
return True

# unions declared as Union[A, B] fall through to this check, even on python 3.10+
# unions declared as Union[A, B] fall through to this check
# even on python 3.10+

annotation_origin = getattr(annotation, "__origin__", None)

Expand Down
4 changes: 2 additions & 2 deletions strawberry/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Union,
cast,
)

from typing_extensions import Annotated, get_args, get_origin

from strawberry.annotation import StrawberryAnnotation
Expand All @@ -25,7 +24,8 @@
from .exceptions import MultipleStrawberryArgumentsError, UnsupportedTypeError
from .scalars import is_scalar
from .types.types import TypeDefinition
from .unset import UNSET as _deprecated_UNSET, _deprecated_is_unset # noqa
from .unset import UNSET as _deprecated_UNSET
from .unset import _deprecated_is_unset # noqa


if TYPE_CHECKING:
Expand Down
1 change: 0 additions & 1 deletion strawberry/asgi/test/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
from typing import Dict, Mapping, Optional

from typing_extensions import Literal

from strawberry.test import BaseGraphQLTestClient
Expand Down
1 change: 0 additions & 1 deletion strawberry/auto.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import Any, Optional, Union, cast

from typing_extensions import Annotated, get_args, get_origin

from strawberry.type import StrawberryType
Expand Down
6 changes: 4 additions & 2 deletions strawberry/chalice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def get_root_value(self, request: Request) -> Optional[object]:
@staticmethod
def render_graphiql() -> str:
"""
Returns a string containing the html for the graphiql webpage. It also caches the
result using lru cache. This saves loading from disk each time it is invoked.
Returns a string containing the html for the graphiql webpage. It also caches
the result using lru cache.
This saves loading from disk each time it is invoked.

Returns:
The GraphiQL html page as a string
"""
Expand Down
1 change: 0 additions & 1 deletion strawberry/channels/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Optional,
Sequence,
)

from typing_extensions import Literal, Protocol, TypedDict

from channels.consumer import AsyncConsumer
Expand Down
1 change: 0 additions & 1 deletion strawberry/codegen/query_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Callable, Iterable, List, Optional, Tuple, Type, Union, cast

from typing_extensions import Literal, Protocol

from graphql import (
Expand Down
1 change: 0 additions & 1 deletion strawberry/codegen/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from enum import EnumMeta
from typing import List, Optional, Type, Union

from typing_extensions import Literal


Expand Down
1 change: 0 additions & 1 deletion strawberry/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dataclasses
import inspect
from typing import Any, Callable, List, Optional, TypeVar

from typing_extensions import Annotated

from graphql import DirectiveLocation
Expand Down
2 changes: 1 addition & 1 deletion strawberry/experimental/pydantic/conversion_types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from typing import Any, Dict, Optional, TypeVar
from typing_extensions import Protocol

from pydantic import BaseModel
from typing_extensions import Protocol

from strawberry.types.types import TypeDefinition

Expand Down
3 changes: 1 addition & 2 deletions strawberry/experimental/pydantic/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
cast,
)

from pydantic.fields import ModelField

from graphql import GraphQLResolveInfo
from pydantic.fields import ModelField

from strawberry.annotation import StrawberryAnnotation
from strawberry.auto import StrawberryAuto
Expand Down
3 changes: 2 additions & 1 deletion strawberry/experimental/pydantic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def get_default_factory_for_field(
"""
Gets the default factory for a pydantic field.

Handles mutable defaults when making the dataclass by using pydantic's smart_deepcopy
Handles mutable defaults when making the dataclass by
using pydantic's smart_deepcopy

Returns optionally a NoArgAnyCallable representing a default_factory parameter
"""
Expand Down
4 changes: 2 additions & 2 deletions strawberry/ext/mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import warnings
from decimal import Decimal
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union, cast

from typing_extensions import Final

import mypy
Expand Down Expand Up @@ -70,7 +69,8 @@

# To be compatible with user who don't use pydantic
try:
from pydantic.mypy import METADATA_KEY as PYDANTIC_METADATA_KEY, PydanticModelField
from pydantic.mypy import METADATA_KEY as PYDANTIC_METADATA_KEY
from pydantic.mypy import PydanticModelField
except ImportError:
PYDANTIC_METADATA_KEY = ""

Expand Down
3 changes: 2 additions & 1 deletion strawberry/extensions/query_depth_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def determine_depth(
return depth_so_far

if isinstance(node, FieldNode):
# by default, ignore the introspection fields which begin with double underscores
# by default, ignore the introspection fields which begin
# with double underscores
should_ignore = is_introspection_key(node.name.value) or is_ignored(
node, ignore
)
Expand Down
3 changes: 1 addition & 2 deletions strawberry/extensions/tracing/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from inspect import isawaitable
from typing import Any, Callable, Dict, Optional

from graphql import GraphQLResolveInfo
from opentelemetry import trace
from opentelemetry.trace import Span, SpanKind, Tracer

from graphql import GraphQLResolveInfo

from strawberry.extensions import Extension
from strawberry.extensions.utils import get_path_from_info
from strawberry.types.execution import ExecutionContext
Expand Down
8 changes: 2 additions & 6 deletions strawberry/federation/enum.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from typing import Any, Callable, Iterable, Optional, Union, overload

from strawberry.enum import (
EnumType,
EnumValueDefinition,
_process_enum,
enum_value as base_enum_value,
)
from strawberry.enum import EnumType, EnumValueDefinition, _process_enum
from strawberry.enum import enum_value as base_enum_value


def enum_value(
Expand Down
4 changes: 2 additions & 2 deletions strawberry/federation/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
Union,
overload,
)

from typing_extensions import Literal

from strawberry.field import _RESOLVER_TYPE, StrawberryField, field as base_field
from strawberry.field import _RESOLVER_TYPE, StrawberryField
from strawberry.field import field as base_field
from strawberry.permission import BasePermission
from strawberry.unset import UNSET

Expand Down
3 changes: 2 additions & 1 deletion strawberry/federation/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
overload,
)

from strawberry.field import StrawberryField, field as base_field
from strawberry.field import StrawberryField
from strawberry.field import field as base_field
from strawberry.object_type import type as base_type
from strawberry.unset import UNSET
from strawberry.utils.typing import __dataclass_transform__
Expand Down
2 changes: 1 addition & 1 deletion strawberry/federation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from itertools import chain
from typing import Any, Dict, Iterable, List, Optional, Type, Union, cast

from graphql import ExecutionContext as GraphQLExecutionContext
from graphql import (
ExecutionContext as GraphQLExecutionContext,
GraphQLError,
GraphQLField,
GraphQLInterfaceType,
Expand Down
1 change: 0 additions & 1 deletion strawberry/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
Union,
overload,
)

from typing_extensions import Literal

from strawberry.annotation import StrawberryAnnotation
Expand Down
1 change: 0 additions & 1 deletion strawberry/http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from dataclasses import dataclass
from typing import Any, Dict, List, Mapping, Optional

from typing_extensions import TypedDict

from graphql.error.graphql_error import format_error as format_graphql_error
Expand Down
4 changes: 2 additions & 2 deletions strawberry/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .field import field


# Mutations and subscriptions are field, we might want to separate things in the long run
# for example to provide better errors
# Mutations and subscriptions are field, we might want to separate
# things in the long run for example to provide better errors
mutation = field
subscription = partial(field, is_subscription=True)
Loading