Skip to content

Commit

Permalink
refactor: bump ruff's minimum python version to 3.8 and remove remain…
Browse files Browse the repository at this point in the history
…ing python 3.7 code (#2995)

Co-authored-by: Patrick Arminio <[email protected]>
  • Loading branch information
bellini666 and patrick91 authored Aug 8, 2023
1 parent 306e3db commit 9444c30
Show file tree
Hide file tree
Showing 41 changed files with 42 additions and 154 deletions.
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Release type: minor

This release updates Strawberry's codebase to use new features in Python 3.8.
It also removes `backports.cached-property` from our dependencies, as we can
now rely on the standard library's `functools.cached_property`.
5 changes: 1 addition & 4 deletions docs/types/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ class StrawberryLogger:
if logger_kwargs.get("stack_info") is None:
logger_kwargs["stack_info"] = True

# stacklevel was added in version 3.8
# https://docs.python.org/3/library/logging.html#logging.Logger.debug
if sys.version_info >= (3, 8):
logger_kwargs["stacklevel"] = 3
logger_kwargs["stacklevel"] = 3

cls.logger.error(error, exc_info=error.original_error, **logger_kwargs)
```
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ aiohttp = {version = "^3.7.4.post0", optional = true}
fastapi = {version = ">=0.65.2", optional = true}
starlite = {version = ">=1.48.0", optional = true, python = ">=3.8"}
channels = {version = ">=3.0.5", optional = true}
"backports.cached-property" = {version = "^1.0.2", python = "<3.8"}
astunparse = {version = "^1.6.3", python = "<3.9"}
libcst = {version = ">=0.4.7", optional = true}
rich = {version = ">=12.0.0", optional = true}
Expand Down Expand Up @@ -191,7 +190,7 @@ stubPath = ""
[tool.ruff]
line-length = 88
select = ["ALL"]
target-version = "py37"
target-version = "py38"
ignore = [
# https://github.com/astral-sh/ruff/pull/4427
# equivalent to keep-runtime-typing
Expand Down
2 changes: 1 addition & 1 deletion strawberry/channels/handlers/http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import dataclasses
import json
from functools import cached_property
from io import BytesIO
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union
from urllib.parse import parse_qs
Expand All @@ -23,7 +24,6 @@
from strawberry.http.types import FormData
from strawberry.http.typevars import Context, RootValue
from strawberry.unset import UNSET
from strawberry.utils.cached_property import cached_property
from strawberry.utils.graphiql import get_graphiql_html

from .base import ChannelsConsumer
Expand Down
2 changes: 1 addition & 1 deletion strawberry/directive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import dataclasses
from functools import cached_property
from typing import TYPE_CHECKING, Any, Callable, Generic, List, Optional, TypeVar
from typing_extensions import Annotated

Expand All @@ -13,7 +14,6 @@
StrawberryResolver,
)
from strawberry.unset import UNSET
from strawberry.utils.cached_property import cached_property

if TYPE_CHECKING:
import inspect
Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional, Set, Union

from graphql import GraphQLError

from strawberry.utils.cached_property import cached_property

from .duplicated_type_name import DuplicatedTypeName
from .exception import StrawberryException, UnableToFindExceptionSource
from .handler import setup_exception_handler
Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/duplicated_type_name.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional, Type

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

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

from abc import ABC, abstractmethod
from functools import cached_property
from typing import TYPE_CHECKING, Optional

from strawberry.utils.cached_property import cached_property
from strawberry.utils.str_converters import to_kebab_case

if TYPE_CHECKING:
Expand Down
11 changes: 3 additions & 8 deletions strawberry/exceptions/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from .exception import StrawberryException, UnableToFindExceptionSource

if sys.version_info >= (3, 8):
original_threading_exception_hook = threading.excepthook
else:
original_threading_exception_hook = None
original_threading_exception_hook = threading.excepthook


ExceptionHandler = Callable[
Expand Down Expand Up @@ -83,13 +80,11 @@ def strawberry_threading_exception_handler(
def reset_exception_handler() -> None:
sys.excepthook = sys.__excepthook__

if sys.version_info >= (3, 8):
threading.excepthook = original_threading_exception_hook
threading.excepthook = original_threading_exception_hook


def setup_exception_handler() -> None:
if should_use_rich_exceptions():
sys.excepthook = strawberry_exception_handler

if sys.version_info >= (3, 8):
threading.excepthook = strawberry_threading_exception_handler
threading.excepthook = strawberry_threading_exception_handler
2 changes: 1 addition & 1 deletion strawberry/exceptions/invalid_argument_type.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional

from strawberry.type import get_object_definition
from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder
Expand Down
2 changes: 1 addition & 1 deletion strawberry/exceptions/invalid_union_type.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from functools import cached_property
from inspect import getframeinfo, stack
from pathlib import Path
from typing import TYPE_CHECKING, Optional, Type

from strawberry.exceptions.utils.source_finder import SourceFinder
from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/missing_arguments_annotations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, List, Optional

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/missing_field_annotation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional, Type

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/missing_return_annotation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/not_a_strawberry_enum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/object_is_not_a_class.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

from enum import Enum
from functools import cached_property
from typing import TYPE_CHECKING, Optional

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/object_is_not_an_enum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional, Type

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/private_strawberry_field.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Optional, Type

from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException
from .utils.source_finder import SourceFinder

Expand Down
2 changes: 1 addition & 1 deletion strawberry/exceptions/scalar_already_registered.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Optional

from strawberry.exceptions.utils.source_finder import SourceFinder
from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException

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

from functools import cached_property
from typing import TYPE_CHECKING, Optional

from strawberry.exceptions.utils.source_finder import SourceFinder
from strawberry.utils.cached_property import cached_property

from .exception import StrawberryException

Expand Down
3 changes: 1 addition & 2 deletions strawberry/exceptions/utils/source_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import importlib.util
import sys
from dataclasses import dataclass
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Type, cast

from strawberry.utils.cached_property import cached_property

from ..exception_source import ExceptionSource

if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions strawberry/extensions/field_extension.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

import itertools
from functools import cached_property
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Union

from strawberry.utils.cached_property import cached_property

if TYPE_CHECKING:
from strawberry.field import StrawberryField
from strawberry.types import Info
Expand Down
2 changes: 1 addition & 1 deletion strawberry/extensions/tracing/datadog.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import hashlib
from functools import cached_property
from inspect import isawaitable
from typing import TYPE_CHECKING, Any, Callable, Generator, Iterator, Optional

from ddtrace import Span, tracer

from strawberry.extensions import LifecycleStep, SchemaExtension
from strawberry.extensions.tracing.utils import should_skip_tracing
from strawberry.utils.cached_property import cached_property

if TYPE_CHECKING:
from graphql import GraphQLResolveInfo
Expand Down
2 changes: 1 addition & 1 deletion strawberry/extensions/tracing/sentry.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import hashlib
from functools import cached_property
from inspect import isawaitable
from typing import TYPE_CHECKING, Any, Callable, Generator, Optional

from sentry_sdk import configure_scope, start_span

from strawberry.extensions import SchemaExtension
from strawberry.extensions.tracing.utils import should_skip_tracing
from strawberry.utils.cached_property import cached_property

if TYPE_CHECKING:
from graphql import GraphQLResolveInfo
Expand Down
3 changes: 1 addition & 2 deletions strawberry/federation/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import defaultdict
from copy import copy
from functools import partial
from functools import cached_property, partial
from itertools import chain
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -31,7 +31,6 @@
from strawberry.printer import print_schema
from strawberry.schema import Schema as BaseSchema
from strawberry.types.types import StrawberryObjectDefinition
from strawberry.utils.cached_property import cached_property
from strawberry.utils.inspect import get_func_args

from .schema_directive import StrawberryFederationSchemaDirective
Expand Down
2 changes: 1 addition & 1 deletion strawberry/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dataclasses
import inspect
import sys
from functools import cached_property
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -30,7 +31,6 @@
has_object_definition,
)
from strawberry.union import StrawberryUnion
from strawberry.utils.cached_property import cached_property

from .types.fields.resolver import StrawberryResolver

Expand Down
2 changes: 1 addition & 1 deletion strawberry/relay/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from collections.abc import Callable
from functools import cached_property
from typing import TYPE_CHECKING, Optional, Type, cast

from strawberry.exceptions.exception import StrawberryException
from strawberry.exceptions.utils.source_finder import SourceFinder
from strawberry.utils.cached_property import cached_property

if TYPE_CHECKING:
from strawberry.exceptions.exception_source import ExceptionSource
Expand Down
2 changes: 1 addition & 1 deletion strawberry/schema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_type_by_name(
raise NotImplementedError

@abstractmethod
@lru_cache()
@lru_cache
def get_directive_by_name(self, graphql_name: str) -> Optional[StrawberryDirective]:
raise NotImplementedError

Expand Down
4 changes: 2 additions & 2 deletions strawberry/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_extensions(

return extensions

@lru_cache()
@lru_cache
def get_type_by_name(
self, name: str
) -> Optional[
Expand Down Expand Up @@ -220,7 +220,7 @@ def get_field_for_type(
None,
)

@lru_cache()
@lru_cache
def get_directive_by_name(self, graphql_name: str) -> Optional[StrawberryDirective]:
return next(
(
Expand Down
Loading

0 comments on commit 9444c30

Please sign in to comment.