Skip to content

Commit

Permalink
chore(deps): update dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bellini666 committed Dec 8, 2024
1 parent 21c99df commit 62dc994
Show file tree
Hide file tree
Showing 43 changed files with 357 additions and 312 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- id: venv
run: echo "python-path=$(poetry env info --path)/bin/python3" >> "$GITHUB_OUTPUT"
- name: Check for pyright errors
uses: jakebailey/pyright-action@v1
uses: jakebailey/pyright-action@v2
with:
python-path: ${{ steps.venv.outputs.python-path }}
tests:
Expand All @@ -46,18 +46,18 @@ jobs:
- 4.2.*
- 5.0.*
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
mode:
- std
- geos
exclude:
# Django 5.0 only supports python 3.10+
- django-version: 5.0.*
python-version: "3.9"
python-version: '3.9'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -81,6 +81,6 @@ jobs:
- name: Test with pytest
run: poetry run pytest --showlocals -vvv --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: check-xml
- id: check-symlinks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
rev: v0.8.2
hooks:
- id: ruff-format
- id: ruff
Expand Down
264 changes: 147 additions & 117 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pytest-django = "^4.1.0"
pytest-mock = "^3.5.1"
pytest-snapshot = "^0.9.0"
pytest-watch = "^4.2.0"
ruff = "^0.7.3"
ruff = "^0.8.2"
django-polymorphic = "^3.1.0"
setuptools = "^75.1.0"
psycopg2 = "^2.9.9"
Expand Down Expand Up @@ -132,6 +132,7 @@ extend-ignore = [
"TRY003",
"PLR6301",
"PLC0415",
"TCH002",
# ruff formatter recommends to disable those
"COM812",
"COM819",
Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/auth/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def resolve_logout(info: Info) -> bool:

class DjangoRegisterMutation(DjangoCreateMutation):
def create(self, data: dict[str, Any], *, info: Info):
model = cast(type["AbstractBaseUser"], self.django_model)
model = cast("type[AbstractBaseUser]", self.django_model)
assert model is not None

password = data.pop("password")
Expand Down
4 changes: 2 additions & 2 deletions strawberry_django/extensions/django_cache_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def __init__(
*,
execution_context: Optional[ExecutionContext] = None,
):
super().__init__(execution_context=cast(ExecutionContext, execution_context))
super().__init__(execution_context=cast("ExecutionContext", execution_context))

self.cache = caches[cache_name]
self.timeout = timeout or DEFAULT_TIMEOUT
# Use same key generating function as functools.lru_cache as default
self.hash_fn = hash_fn or (lambda args, kwargs: _make_key(args, kwargs, False))

def execute_cached(self, func, *args, **kwargs):
hash_key = cast(str, self.hash_fn(args, kwargs))
hash_key = cast("str", self.hash_fn(args, kwargs))
cache_result = self.cache.get(hash_key)
if cache_result is not None:
return cache_result
Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def django_type(self) -> type[WithStrawberryDjangoObjectDefinition] | None:
object_definition.origin, (relay.Connection, OffsetPaginated)
):
origin_specialized_type_var_map = (
get_specialized_type_var_map(cast(type, origin)) or {}
get_specialized_type_var_map(cast("type", origin)) or {}
)
origin = origin_specialized_type_var_map.get("NodeType")

Expand Down
22 changes: 11 additions & 11 deletions strawberry_django/fields/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from strawberry.extensions.field_extension import FieldExtension
from strawberry.types.field import _RESOLVER_TYPE # noqa: PLC2701
from strawberry.types.fields.resolver import StrawberryResolver
from strawberry.types.info import Info # noqa: TCH002
from strawberry.types.info import Info
from strawberry.utils.await_maybe import await_maybe
from typing_extensions import TypeAlias

Expand Down Expand Up @@ -376,7 +376,7 @@ def default_resolver(
# If this is a nested field, call get_result instead because we want
# to retrieve the queryset from its RelatedManager
retval = cast(
models.QuerySet,
"models.QuerySet",
getattr(root, field.django_name or field.python_name).all(),
)
else:
Expand All @@ -394,7 +394,7 @@ def default_resolver(
required=True,
)

return cast(Iterable[Any], retval)
return cast("Iterable[Any]", retval)

default_resolver.can_optimize = True # type: ignore

Expand All @@ -415,7 +415,7 @@ def resolve(
**kwargs: Any,
) -> Any:
assert self.connection_type is not None
nodes = cast(Iterable[relay.Node], next_(source, info, **kwargs))
nodes = cast("Iterable[relay.Node]", next_(source, info, **kwargs))

# We have a single resolver for both sync and async, so we need to check if
# nodes is awaitable or not and resolve it accordingly
Expand Down Expand Up @@ -457,7 +457,7 @@ def apply(self, field: StrawberryField) -> None:
)

field.arguments = _get_field_arguments_for_extensions(field)
self.paginated_type = cast(type[OffsetPaginated], field.type)
self.paginated_type = cast("type[OffsetPaginated]", field.type)

def resolve(
self,
Expand All @@ -471,10 +471,10 @@ def resolve(
**kwargs: Any,
) -> Any:
assert self.paginated_type is not None
queryset = cast(models.QuerySet, next_(source, info, **kwargs))
queryset = cast("models.QuerySet", next_(source, info, **kwargs))

def get_queryset(queryset):
return cast(StrawberryDjangoField, info._field).get_queryset(
return cast("StrawberryDjangoField", info._field).get_queryset(
queryset,
info,
pagination=pagination,
Expand Down Expand Up @@ -620,7 +620,7 @@ def field(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: bool | None = None,
) -> Any:
"""Annotate a method or property as a Django GraphQL field.
Expand Down Expand Up @@ -690,7 +690,7 @@ def node(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: bool | None = None,
) -> Any:
"""Annotate a property to create a relay query field.
Expand Down Expand Up @@ -812,7 +812,7 @@ def connection(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: bool | None = None,
) -> Any:
"""Annotate a property or a method to create a relay connection field.
Expand Down Expand Up @@ -993,7 +993,7 @@ def offset_paginated(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: bool | None = None,
) -> Any:
"""Annotate a property or a method to create a relay connection field.
Expand Down
4 changes: 2 additions & 2 deletions strawberry_django/fields/filter_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def filter_field(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: bool | None = None,
) -> Any:
"""Annotates a method or property as a Django filter field.
Expand Down Expand Up @@ -342,7 +342,7 @@ def order_field(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: bool | None = None,
) -> Any:
"""Annotates a method or property as a Django filter field.
Expand Down
8 changes: 4 additions & 4 deletions strawberry_django/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def process_filters(
assert has_object_definition(field_value)

queryset, sub_q = process_filters(
cast(WithStrawberryObjectDefinition, field_value),
cast("WithStrawberryObjectDefinition", field_value),
queryset,
info,
prefix,
Expand Down Expand Up @@ -231,7 +231,7 @@ def process_filters(
queryset = _process_deprecated_filter(filter_method, info, queryset)
elif has_object_definition(field_value):
queryset, sub_q = process_filters(
cast(WithStrawberryObjectDefinition, field_value),
cast("WithStrawberryObjectDefinition", field_value),
queryset,
info,
f"{prefix}{field_name}__",
Expand Down Expand Up @@ -264,7 +264,7 @@ def apply(
return queryset

queryset, q = process_filters(
cast(WithStrawberryObjectDefinition, filters), queryset, info
cast("WithStrawberryObjectDefinition", filters), queryset, info
)
if q:
queryset = queryset.filter(q)
Expand All @@ -289,7 +289,7 @@ def arguments(self) -> list[StrawberryArgument]:
arguments = []
if self.base_resolver is None:
filters = self.get_filters()
origin = cast(WithStrawberryObjectDefinition, self.origin)
origin = cast("WithStrawberryObjectDefinition", self.origin)
is_root_query = origin.__strawberry_definition__.name == "Query"

if (
Expand Down
6 changes: 3 additions & 3 deletions strawberry_django/integrations/guardian.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def get_object_permission_models(
model: Union[models.Model, type[models.Model]],
) -> ObjectPermissionModels:
return ObjectPermissionModels(
user=cast(UserObjectPermissionBase, get_user_obj_perms_model(model)),
group=cast(GroupObjectPermissionBase, get_group_obj_perms_model(model)),
user=cast("UserObjectPermissionBase", get_user_obj_perms_model(model)),
group=cast("GroupObjectPermissionBase", get_group_obj_perms_model(model)),
)


def get_user_or_anonymous(user: UserType) -> UserType:
username = guardian_settings.ANONYMOUS_USER_NAME or ""
if user.is_anonymous and user.get_username() != username:
with contextlib.suppress(get_user_model().DoesNotExist):
return cast(UserType, _get_anonymous_user())
return cast("UserType", _get_anonymous_user())
return user
4 changes: 2 additions & 2 deletions strawberry_django/mutations/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def mutation(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: Optional[bool] = None,
) -> Any:
"""Annotate a property or a method to create a mutation field."""
f = DjangoMutationBase(
Expand Down Expand Up @@ -213,7 +213,7 @@ def input_mutation(
# This init parameter is used by pyright to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init: Literal[True, False, None] = None,
init: Optional[bool] = None,
) -> Any:
"""Annotate a property or a method to create an input mutation field."""
extensions = [*list(extensions), InputMutationExtension()]
Expand Down
27 changes: 15 additions & 12 deletions strawberry_django/mutations/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def parse_input(
return data.resolve_node_sync(info, required=True)

if isinstance(data, NodeInput):
pk = cast(Any, parse_input(info, getattr(data, "id", UNSET), key_attr=key_attr))
pk = cast(
"Any", parse_input(info, getattr(data, "id", UNSET), key_attr=key_attr)
)
parsed = {}
for field in dataclasses.fields(data):
if field.name == "id":
Expand All @@ -172,7 +174,7 @@ def parse_input(

return ParsedObject(
pk=pk,
data=parsed if len(parsed) else None,
data=parsed or None,
)

if isinstance(data, (OneToOneInput, OneToManyInput)):
Expand All @@ -190,13 +192,14 @@ def parse_input(

return ParsedObjectList(
add=cast(
list[InputListTypes], parse_input(info, data.add, key_attr=key_attr)
"list[InputListTypes]", parse_input(info, data.add, key_attr=key_attr)
),
remove=cast(
list[InputListTypes], parse_input(info, data.remove, key_attr=key_attr)
"list[InputListTypes]",
parse_input(info, data.remove, key_attr=key_attr),
),
set=cast(
list[InputListTypes], parse_input(info, data.set, key_attr=key_attr)
"list[InputListTypes]", parse_input(info, data.set, key_attr=key_attr)
),
)

Expand Down Expand Up @@ -263,7 +266,7 @@ def prepare_create_update(
):
value, value_data = _parse_data( # noqa: PLW2901
info,
cast(type[Model], field.related_model),
cast("type[Model]", field.related_model),
value,
key_attr=key_attr,
)
Expand Down Expand Up @@ -418,7 +421,7 @@ def update(
# Unwrap lazy objects since they have a proxy __iter__ method that will make
# them iterables even if the wrapped object isn't
if isinstance(instance, LazyObject):
instance = cast(_M, instance.__reduce__()[1][0])
instance = cast("_M", instance.__reduce__()[1][0])

if isinstance(instance, Iterable):
instances = list(instance)
Expand Down Expand Up @@ -482,7 +485,7 @@ def delete(info: Info, instance: _M | Iterable[_M], *, data=None) -> _M | list[_
# Unwrap lazy objects since they have a proxy __iter__ method that will make
# them iterables even if the wrapped object isn't
if isinstance(instance, LazyObject):
instance = cast(_M, instance.__reduce__()[1][0])
instance = cast("_M", instance.__reduce__()[1][0])

if isinstance(instance, Iterable):
many = True
Expand Down Expand Up @@ -511,7 +514,7 @@ def update_field(info: Info, instance: Model, field: models.Field, value: Any):
and isinstance(field, models.ForeignObject)
and not isinstance(value, Model)
):
value, data = _parse_pk(value, cast(type[Model], field.related_model))
value, data = _parse_pk(value, cast("type[Model]", field.related_model))

field.save_form_data(instance, value)
# If data was passed to the foreign key, update it recursively
Expand Down Expand Up @@ -578,7 +581,7 @@ def update_m2m(
need_remove_cache = need_remove_cache or bool(values)
for v in values:
obj, data = _parse_data(
info, cast(type[Model], manager.model), v, key_attr=key_attr
info, cast("type[Model]", manager.model), v, key_attr=key_attr
)
if obj:
data.pop(key_attr, None)
Expand Down Expand Up @@ -639,7 +642,7 @@ def update_m2m(
for v in value.add or []:
obj, data = _parse_data(
info,
cast(type[Model], manager.model),
cast("type[Model]", manager.model),
v,
key_attr=key_attr,
)
Expand All @@ -664,7 +667,7 @@ def update_m2m(
need_remove_cache = need_remove_cache or bool(value.remove)
for v in value.remove or []:
obj, data = _parse_data(
info, cast(type[Model], manager.model), v, key_attr=key_attr
info, cast("type[Model]", manager.model), v, key_attr=key_attr
)
data.pop(key_attr, None)
assert not data
Expand Down
Loading

0 comments on commit 62dc994

Please sign in to comment.