Improve code style

This commit is contained in:
NateScarlet 2019-06-12 23:19:22 +08:00
parent 2909928363
commit e4f9bbea96
No known key found for this signature in database
GPG Key ID: 5C242793B070309C

View File

@ -131,20 +131,23 @@ class DjangoConnectionField(ConnectionField):
root, root,
info, info,
**kwargs): **kwargs):
# pylint: disable=R0913,W0221
# By current `connection_from_list_slice` implementation,
# `last` means last N items in the selection,
# and when use `last` with `first`, `last` means last N items in first N items.
first = kwargs.get("first") first = kwargs.get("first")
last = kwargs.get("last") last = kwargs.get("last")
if not (first is None or first > 0): if first is not None and first <= 0:
raise ValueError( raise ValueError(
"`first` argument must be positive, got `{first}`".format(**locals())) "`first` argument must be positive, got `{first}`".format(first=first))
if not (last is None or last > 0): if last is not None and last <= 0:
raise ValueError( raise ValueError(
"`last` argument must be positive, got `{last}`".format(**locals())) "`last` argument must be positive, got `{last}`".format(last=last))
if enforce_first_or_last and not (first or last): if enforce_first_or_last and not (first or last):
raise ValueError( raise ValueError(
"You must provide a `first` or `last` value " "You must provide a `first` or `last` value "
"to properly paginate the `{info.field_name}` connection.".format(**locals())) "to properly paginate the `{info.field_name}` connection.".format(info=info))
if not max_limit: if not max_limit:
pass pass
@ -155,7 +158,8 @@ class DjangoConnectionField(ConnectionField):
if count > max_limit: if count > max_limit:
raise ValueError(("Requesting {count} records " raise ValueError(("Requesting {count} records "
"on the `{info.field_name}` connection " "on the `{info.field_name}` connection "
"exceeds the limit of {max_limit} records.").format(**locals())) "exceeds the limit of {max_limit} records.").format(
count=count, info=info, max_limit=max_limit))
iterable = resolver(root, info, **kwargs) iterable = resolver(root, info, **kwargs)
queryset = cls.resolve_queryset(connection, default_manager, info, kwargs) queryset = cls.resolve_queryset(connection, default_manager, info, kwargs)