Add pyupgrade

This commit is contained in:
Kien Dang 2023-08-05 13:44:50 +08:00
parent add11cb9a6
commit 4da0841ec2
7 changed files with 15 additions and 21 deletions

View File

@ -2,6 +2,7 @@ select = [
"E", # pycodestyle "E", # pycodestyle
"W", # pycodestyle "W", # pycodestyle
"F", # pyflake "F", # pyflake
"UP", # pyupgrade
] ]
ignore = [ ignore = [

View File

@ -161,9 +161,7 @@ def get_django_field_description(field):
@singledispatch @singledispatch
def convert_django_field(field, registry=None): def convert_django_field(field, registry=None):
raise Exception( raise Exception(
"Don't know how to convert the Django field {} ({})".format( f"Don't know how to convert the Django field {field} ({field.__class__})"
field, field.__class__
)
) )

View File

@ -348,9 +348,9 @@ def test_fk_id_in_filter(query):
schema = Schema(query=query) schema = Schema(query=query)
query = """ query = f"""
query {{ query {{
articles (reporter_In: [{}, {}]) {{ articles (reporter_In: [{john_doe.id}, {jean_bon.id}]) {{
edges {{ edges {{
node {{ node {{
headline headline
@ -361,10 +361,7 @@ def test_fk_id_in_filter(query):
}} }}
}} }}
}} }}
""".format( """
john_doe.id,
jean_bon.id,
)
result = schema.execute(query) result = schema.execute(query)
assert not result.errors assert not result.errors
assert result.data["articles"]["edges"] == [ assert result.data["articles"]["edges"] == [

View File

@ -27,8 +27,8 @@ def get_form_field_description(field):
@singledispatch @singledispatch
def convert_form_field(field): def convert_form_field(field):
raise ImproperlyConfigured( raise ImproperlyConfigured(
"Don't know how to convert the Django form field %s (%s) " "Don't know how to convert the Django form field {} ({}) "
"to Graphene type" % (field, field.__class__) "to Graphene type".format(field, field.__class__)
) )

View File

@ -8,9 +8,7 @@ class Registry:
assert issubclass( assert issubclass(
cls, DjangoObjectType cls, DjangoObjectType
), 'Only DjangoObjectTypes can be registered, received "{}"'.format( ), f'Only DjangoObjectTypes can be registered, received "{cls.__name__}"'
cls.__name__
)
assert cls._meta.registry == self, "Registry for a Model have to match." assert cls._meta.registry == self, "Registry for a Model have to match."
# assert self.get_type_for_model(cls._meta.model) == cls, ( # assert self.get_type_for_model(cls._meta.model) == cls, (
# 'Multiple DjangoObjectTypes registered for "{}"'.format(cls._meta.model) # 'Multiple DjangoObjectTypes registered for "{}"'.format(cls._meta.model)

View File

@ -13,8 +13,8 @@ from .types import DictType
@singledispatch @singledispatch
def get_graphene_type_from_serializer_field(field): def get_graphene_type_from_serializer_field(field):
raise ImproperlyConfigured( raise ImproperlyConfigured(
"Don't know how to convert the serializer field %s (%s) " "Don't know how to convert the serializer field {} ({}) "
"to Graphene type" % (field, field.__class__) "to Graphene type".format(field, field.__class__)
) )

View File

@ -150,7 +150,7 @@ class DjangoObjectType(ObjectType):
interfaces=(), interfaces=(),
convert_choices_to_enum=True, convert_choices_to_enum=True,
_meta=None, _meta=None,
**options **options,
): ):
assert is_valid_django_model(model), ( assert is_valid_django_model(model), (
'You need to pass a valid Django Model in {}.Meta, received "{}".' 'You need to pass a valid Django Model in {}.Meta, received "{}".'
@ -240,9 +240,9 @@ class DjangoObjectType(ObjectType):
) )
if connection is not None: if connection is not None:
assert issubclass(connection, Connection), ( assert issubclass(
"The connection must be a Connection. Received {}" connection, Connection
).format(connection.__name__) ), f"The connection must be a Connection. Received {connection.__name__}"
if not _meta: if not _meta:
_meta = DjangoObjectTypeOptions(cls) _meta = DjangoObjectTypeOptions(cls)
@ -273,7 +273,7 @@ class DjangoObjectType(ObjectType):
if isinstance(root, cls): if isinstance(root, cls):
return True return True
if not is_valid_django_model(root.__class__): if not is_valid_django_model(root.__class__):
raise Exception(('Received incompatible instance "{}".').format(root)) raise Exception(f'Received incompatible instance "{root}".')
if cls._meta.model._meta.proxy: if cls._meta.model._meta.proxy:
model = root._meta.model model = root._meta.model