From 81787d9cdd93d37cb9801df4ae05c15185da07b7 Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Sun, 25 Sep 2022 17:24:42 +0200 Subject: [PATCH] Format with pre-commit dedent docs/schema.py to allow formatting --- .github/ISSUE_TEMPLATE/bug_report.md | 6 +- CONTRIBUTING.md | 2 +- MANIFEST.in | 2 +- docs/schema.py | 79 +++-- docs/tutorial-plain.rst | 4 +- .../ingredients/fixtures/ingredients.json | 53 ++- .../ingredients/migrations/0001_initial.py | 44 ++- .../migrations/0002_auto_20161104_0050.py | 8 +- .../migrations/0003_auto_20181018_1746.py | 6 +- .../cookbook/ingredients/schema.py | 2 +- .../recipes/migrations/0001_initial.py | 60 +++- .../migrations/0002_auto_20161104_0106.py | 24 +- .../migrations/0003_auto_20181018_1728.py | 16 +- .../cookbook-plain/cookbook/recipes/schema.py | 2 +- .../ingredients/fixtures/ingredients.json | 53 ++- .../ingredients/migrations/0001_initial.py | 44 ++- .../migrations/0002_auto_20161104_0050.py | 8 +- .../cookbook/cookbook/ingredients/schema.py | 2 +- .../recipes/migrations/0001_initial.py | 60 +++- .../migrations/0002_auto_20161104_0106.py | 24 +- examples/cookbook/cookbook/recipes/schema.py | 2 +- examples/cookbook/dummy_data.json | 303 +++++++++++++++++- examples/starwars/models.py | 2 - graphene_django/compat.py | 2 +- graphene_django/converter.py | 11 +- graphene_django/debug/middleware.py | 4 +- graphene_django/debug/sql/tracking.py | 7 +- graphene_django/debug/tests/test_query.py | 2 +- graphene_django/fields.py | 6 +- graphene_django/filter/fields.py | 6 +- .../filter/filters/array_filter.py | 2 +- .../filter/filters/global_id_filter.py | 4 +- graphene_django/filter/filters/list_filter.py | 2 +- .../filter/filters/typed_filter.py | 2 +- graphene_django/filter/filterset.py | 4 +- graphene_django/filter/tests/conftest.py | 2 +- graphene_django/filter/tests/test_fields.py | 6 +- .../filter/tests/test_in_filter.py | 22 +- .../filter/tests/test_typed_filter.py | 2 +- graphene_django/forms/mutation.py | 8 +- .../management/commands/graphql_schema.py | 8 +- graphene_django/registry.py | 2 +- graphene_django/rest_framework/mutation.py | 2 +- .../rest_framework/serializer_converter.py | 2 +- graphene_django/settings.py | 5 +- graphene_django/tests/models.py | 10 +- graphene_django/tests/test_command.py | 2 +- graphene_django/tests/test_query.py | 6 +- graphene_django/tests/test_types.py | 6 +- graphene_django/tests/test_utils.py | 6 +- graphene_django/tests/test_views.py | 4 +- graphene_django/types.py | 10 +- graphene_django/utils/testing.py | 2 +- graphene_django/views.py | 2 +- 54 files changed, 738 insertions(+), 227 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 2c933d734..26d84aa48 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -27,8 +27,8 @@ a github repo, https://repl.it or similar (you can use this template as a starti * **Please tell us about your environment:** - - - Version: - - Platform: + + - Version: + - Platform: * **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f9428e978..6a226ab3a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,4 +59,4 @@ Then to produce a HTML version of the documentation: ```sh make html -``` \ No newline at end of file +``` diff --git a/MANIFEST.in b/MANIFEST.in index 045af08f9..1ede730c8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,4 +3,4 @@ recursive-include graphene_django/templates * recursive-include graphene_django/static * include examples/cookbook/cookbook/ingredients/fixtures/ingredients.json -include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json \ No newline at end of file +include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json diff --git a/docs/schema.py b/docs/schema.py index 1de92edf1..058a58723 100644 --- a/docs/schema.py +++ b/docs/schema.py @@ -1,60 +1,57 @@ - import graphene +import graphene - from graphene_django.types import DjangoObjectType +from graphene_django.types import DjangoObjectType - from cookbook.ingredients.models import Category, Ingredient +from cookbook.ingredients.models import Category, Ingredient - class CategoryType(DjangoObjectType): - class Meta: - model = Category - fields = '__all__' +class CategoryType(DjangoObjectType): + class Meta: + model = Category + fields = "__all__" - class IngredientType(DjangoObjectType): - class Meta: - model = Ingredient - fields = '__all__' +class IngredientType(DjangoObjectType): + class Meta: + model = Ingredient + fields = "__all__" - class Query(object): - category = graphene.Field(CategoryType, - id=graphene.Int(), - name=graphene.String()) - all_categories = graphene.List(CategoryType) +class Query: + category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String()) + all_categories = graphene.List(CategoryType) + ingredient = graphene.Field( + IngredientType, id=graphene.Int(), name=graphene.String() + ) + all_ingredients = graphene.List(IngredientType) - ingredient = graphene.Field(IngredientType, - id=graphene.Int(), - name=graphene.String()) - all_ingredients = graphene.List(IngredientType) + def resolve_all_categories(self, info, **kwargs): + return Category.objects.all() - def resolve_all_categories(self, info, **kwargs): - return Category.objects.all() + def resolve_all_ingredients(self, info, **kwargs): + return Ingredient.objects.all() - def resolve_all_ingredients(self, info, **kwargs): - return Ingredient.objects.all() + def resolve_category(self, info, **kwargs): + id = kwargs.get("id") + name = kwargs.get("name") - def resolve_category(self, info, **kwargs): - id = kwargs.get('id') - name = kwargs.get('name') + if id is not None: + return Category.objects.get(pk=id) - if id is not None: - return Category.objects.get(pk=id) + if name is not None: + return Category.objects.get(name=name) - if name is not None: - return Category.objects.get(name=name) + return None - return None + def resolve_ingredient(self, info, **kwargs): + id = kwargs.get("id") + name = kwargs.get("name") - def resolve_ingredient(self, info, **kwargs): - id = kwargs.get('id') - name = kwargs.get('name') + if id is not None: + return Ingredient.objects.get(pk=id) - if id is not None: - return Ingredient.objects.get(pk=id) + if name is not None: + return Ingredient.objects.get(name=name) - if name is not None: - return Ingredient.objects.get(name=name) - - return None \ No newline at end of file + return None diff --git a/docs/tutorial-plain.rst b/docs/tutorial-plain.rst index 43b6da9da..9073c82e4 100644 --- a/docs/tutorial-plain.rst +++ b/docs/tutorial-plain.rst @@ -85,8 +85,8 @@ Make sure the app name in ``cookbook.ingredients.apps.IngredientsConfig`` is set # cookbook/ingredients/apps.py from django.apps import AppConfig - - + + class IngredientsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'cookbook.ingredients' diff --git a/examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json b/examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json index 8625d3c70..213bd8b74 100644 --- a/examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json +++ b/examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json @@ -1 +1,52 @@ -[{"model": "ingredients.category", "pk": 1, "fields": {"name": "Dairy"}}, {"model": "ingredients.category", "pk": 2, "fields": {"name": "Meat"}}, {"model": "ingredients.ingredient", "pk": 1, "fields": {"name": "Eggs", "notes": "Good old eggs", "category": 1}}, {"model": "ingredients.ingredient", "pk": 2, "fields": {"name": "Milk", "notes": "Comes from a cow", "category": 1}}, {"model": "ingredients.ingredient", "pk": 3, "fields": {"name": "Beef", "notes": "Much like milk, this comes from a cow", "category": 2}}, {"model": "ingredients.ingredient", "pk": 4, "fields": {"name": "Chicken", "notes": "Definitely doesn't come from a cow", "category": 2}}] \ No newline at end of file +[ + { + "fields": { + "name": "Dairy" + }, + "model": "ingredients.category", + "pk": 1 + }, + { + "fields": { + "name": "Meat" + }, + "model": "ingredients.category", + "pk": 2 + }, + { + "fields": { + "category": 1, + "name": "Eggs", + "notes": "Good old eggs" + }, + "model": "ingredients.ingredient", + "pk": 1 + }, + { + "fields": { + "category": 1, + "name": "Milk", + "notes": "Comes from a cow" + }, + "model": "ingredients.ingredient", + "pk": 2 + }, + { + "fields": { + "category": 2, + "name": "Beef", + "notes": "Much like milk, this comes from a cow" + }, + "model": "ingredients.ingredient", + "pk": 3 + }, + { + "fields": { + "category": 2, + "name": "Chicken", + "notes": "Definitely doesn't come from a cow" + }, + "model": "ingredients.ingredient", + "pk": 4 + } +] diff --git a/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py b/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py index 04949239f..345cadb9b 100644 --- a/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py +++ b/examples/cookbook-plain/cookbook/ingredients/migrations/0001_initial.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2015-12-04 18:15 -from __future__ import unicode_literals import django.db.models.deletion from django.db import migrations, models @@ -10,24 +8,46 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Category', + name="Category", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), ], ), migrations.CreateModel( - name='Ingredient', + name="Ingredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('notes', models.TextField()), - ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("notes", models.TextField()), + ( + "category", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="ingredients", + to="ingredients.Category", + ), + ), ], ), ] diff --git a/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py b/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py index 359d4fc4c..00fe255ab 100644 --- a/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py +++ b/examples/cookbook-plain/cookbook/ingredients/migrations/0002_auto_20161104_0050.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2016-11-04 00:50 -from __future__ import unicode_literals from django.db import migrations, models @@ -8,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.AlterField( - model_name='ingredient', - name='notes', + model_name="ingredient", + name="notes", field=models.TextField(blank=True, null=True), ), ] diff --git a/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py b/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py index 184e79e4f..8015d1f72 100644 --- a/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py +++ b/examples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py @@ -6,12 +6,12 @@ class Migration(migrations.Migration): dependencies = [ - ('ingredients', '0002_auto_20161104_0050'), + ("ingredients", "0002_auto_20161104_0050"), ] operations = [ migrations.AlterModelOptions( - name='category', - options={'verbose_name_plural': 'Categories'}, + name="category", + options={"verbose_name_plural": "Categories"}, ), ] diff --git a/examples/cookbook-plain/cookbook/ingredients/schema.py b/examples/cookbook-plain/cookbook/ingredients/schema.py index 24a5e9530..b8de8f9ed 100644 --- a/examples/cookbook-plain/cookbook/ingredients/schema.py +++ b/examples/cookbook-plain/cookbook/ingredients/schema.py @@ -16,7 +16,7 @@ class Meta: fields = "__all__" -class Query(object): +class Query: category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String()) all_categories = graphene.List(CategoryType) diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py b/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py index 338c71a1b..fceeb9b7a 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0001_initial.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2015-12-04 18:20 -from __future__ import unicode_literals import django.db.models.deletion from django.db import migrations, models @@ -11,26 +9,62 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.CreateModel( - name='Recipe', + name="Recipe", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('instructions', models.TextField()), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("instructions", models.TextField()), ], ), migrations.CreateModel( - name='RecipeIngredient', + name="RecipeIngredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('amount', models.FloatField()), - ('unit', models.CharField(choices=[('kg', 'Kilograms'), ('l', 'Litres'), ('', 'Units')], max_length=20)), - ('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to='ingredients.Ingredient')), - ('recipes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='amounts', to='recipes.Recipe')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("amount", models.FloatField()), + ( + "unit", + models.CharField( + choices=[("kg", "Kilograms"), ("l", "Litres"), ("", "Units")], + max_length=20, + ), + ), + ( + "ingredient", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="used_by", + to="ingredients.Ingredient", + ), + ), + ( + "recipes", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="amounts", + to="recipes.Recipe", + ), + ), ], ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py index f13539265..015692038 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2016-11-04 01:06 -from __future__ import unicode_literals from django.db import migrations, models @@ -8,18 +6,26 @@ class Migration(migrations.Migration): dependencies = [ - ('recipes', '0001_initial'), + ("recipes", "0001_initial"), ] operations = [ migrations.RenameField( - model_name='recipeingredient', - old_name='recipes', - new_name='recipe', + model_name="recipeingredient", + old_name="recipes", + new_name="recipe", ), migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), + model_name="recipeingredient", + name="unit", + field=models.CharField( + choices=[ + (b"unit", b"Units"), + (b"kg", b"Kilograms"), + (b"l", b"Litres"), + (b"st", b"Shots"), + ], + max_length=20, + ), ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py b/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py index 7a8df493b..c54855b82 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py @@ -6,13 +6,21 @@ class Migration(migrations.Migration): dependencies = [ - ('recipes', '0002_auto_20161104_0106'), + ("recipes", "0002_auto_20161104_0106"), ] operations = [ migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[('unit', 'Units'), ('kg', 'Kilograms'), ('l', 'Litres'), ('st', 'Shots')], max_length=20), + model_name="recipeingredient", + name="unit", + field=models.CharField( + choices=[ + ("unit", "Units"), + ("kg", "Kilograms"), + ("l", "Litres"), + ("st", "Shots"), + ], + max_length=20, + ), ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/schema.py b/examples/cookbook-plain/cookbook/recipes/schema.py index aa7fd2df0..7f40d519e 100644 --- a/examples/cookbook-plain/cookbook/recipes/schema.py +++ b/examples/cookbook-plain/cookbook/recipes/schema.py @@ -16,7 +16,7 @@ class Meta: fields = "__all__" -class Query(object): +class Query: recipe = graphene.Field(RecipeType, id=graphene.Int(), title=graphene.String()) all_recipes = graphene.List(RecipeType) diff --git a/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json b/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json index 8625d3c70..213bd8b74 100644 --- a/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json +++ b/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json @@ -1 +1,52 @@ -[{"model": "ingredients.category", "pk": 1, "fields": {"name": "Dairy"}}, {"model": "ingredients.category", "pk": 2, "fields": {"name": "Meat"}}, {"model": "ingredients.ingredient", "pk": 1, "fields": {"name": "Eggs", "notes": "Good old eggs", "category": 1}}, {"model": "ingredients.ingredient", "pk": 2, "fields": {"name": "Milk", "notes": "Comes from a cow", "category": 1}}, {"model": "ingredients.ingredient", "pk": 3, "fields": {"name": "Beef", "notes": "Much like milk, this comes from a cow", "category": 2}}, {"model": "ingredients.ingredient", "pk": 4, "fields": {"name": "Chicken", "notes": "Definitely doesn't come from a cow", "category": 2}}] \ No newline at end of file +[ + { + "fields": { + "name": "Dairy" + }, + "model": "ingredients.category", + "pk": 1 + }, + { + "fields": { + "name": "Meat" + }, + "model": "ingredients.category", + "pk": 2 + }, + { + "fields": { + "category": 1, + "name": "Eggs", + "notes": "Good old eggs" + }, + "model": "ingredients.ingredient", + "pk": 1 + }, + { + "fields": { + "category": 1, + "name": "Milk", + "notes": "Comes from a cow" + }, + "model": "ingredients.ingredient", + "pk": 2 + }, + { + "fields": { + "category": 2, + "name": "Beef", + "notes": "Much like milk, this comes from a cow" + }, + "model": "ingredients.ingredient", + "pk": 3 + }, + { + "fields": { + "category": 2, + "name": "Chicken", + "notes": "Definitely doesn't come from a cow" + }, + "model": "ingredients.ingredient", + "pk": 4 + } +] diff --git a/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py b/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py index 04949239f..345cadb9b 100644 --- a/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py +++ b/examples/cookbook/cookbook/ingredients/migrations/0001_initial.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2015-12-04 18:15 -from __future__ import unicode_literals import django.db.models.deletion from django.db import migrations, models @@ -10,24 +8,46 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Category', + name="Category", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), ], ), migrations.CreateModel( - name='Ingredient', + name="Ingredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('notes', models.TextField()), - ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=100)), + ("notes", models.TextField()), + ( + "category", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="ingredients", + to="ingredients.Category", + ), + ), ], ), ] diff --git a/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py b/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py index 359d4fc4c..00fe255ab 100644 --- a/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py +++ b/examples/cookbook/cookbook/ingredients/migrations/0002_auto_20161104_0050.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2016-11-04 00:50 -from __future__ import unicode_literals from django.db import migrations, models @@ -8,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.AlterField( - model_name='ingredient', - name='notes', + model_name="ingredient", + name="notes", field=models.TextField(blank=True, null=True), ), ] diff --git a/examples/cookbook/cookbook/ingredients/schema.py b/examples/cookbook/cookbook/ingredients/schema.py index 43b6118a0..4ed9eff13 100644 --- a/examples/cookbook/cookbook/ingredients/schema.py +++ b/examples/cookbook/cookbook/ingredients/schema.py @@ -28,7 +28,7 @@ class Meta: } -class Query(object): +class Query: category = Node.Field(CategoryNode) all_categories = DjangoFilterConnectionField(CategoryNode) diff --git a/examples/cookbook/cookbook/recipes/migrations/0001_initial.py b/examples/cookbook/cookbook/recipes/migrations/0001_initial.py index 338c71a1b..fceeb9b7a 100644 --- a/examples/cookbook/cookbook/recipes/migrations/0001_initial.py +++ b/examples/cookbook/cookbook/recipes/migrations/0001_initial.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2015-12-04 18:20 -from __future__ import unicode_literals import django.db.models.deletion from django.db import migrations, models @@ -11,26 +9,62 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('ingredients', '0001_initial'), + ("ingredients", "0001_initial"), ] operations = [ migrations.CreateModel( - name='Recipe', + name="Recipe", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('instructions', models.TextField()), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("instructions", models.TextField()), ], ), migrations.CreateModel( - name='RecipeIngredient', + name="RecipeIngredient", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('amount', models.FloatField()), - ('unit', models.CharField(choices=[('kg', 'Kilograms'), ('l', 'Litres'), ('', 'Units')], max_length=20)), - ('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='used_by', to='ingredients.Ingredient')), - ('recipes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='amounts', to='recipes.Recipe')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("amount", models.FloatField()), + ( + "unit", + models.CharField( + choices=[("kg", "Kilograms"), ("l", "Litres"), ("", "Units")], + max_length=20, + ), + ), + ( + "ingredient", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="used_by", + to="ingredients.Ingredient", + ), + ), + ( + "recipes", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="amounts", + to="recipes.Recipe", + ), + ), ], ), ] diff --git a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py index f13539265..015692038 100644 --- a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2016-11-04 01:06 -from __future__ import unicode_literals from django.db import migrations, models @@ -8,18 +6,26 @@ class Migration(migrations.Migration): dependencies = [ - ('recipes', '0001_initial'), + ("recipes", "0001_initial"), ] operations = [ migrations.RenameField( - model_name='recipeingredient', - old_name='recipes', - new_name='recipe', + model_name="recipeingredient", + old_name="recipes", + new_name="recipe", ), migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), + model_name="recipeingredient", + name="unit", + field=models.CharField( + choices=[ + (b"unit", b"Units"), + (b"kg", b"Kilograms"), + (b"l", b"Litres"), + (b"st", b"Shots"), + ], + max_length=20, + ), ), ] diff --git a/examples/cookbook/cookbook/recipes/schema.py b/examples/cookbook/cookbook/recipes/schema.py index c7298aacd..ea5ed38f1 100644 --- a/examples/cookbook/cookbook/recipes/schema.py +++ b/examples/cookbook/cookbook/recipes/schema.py @@ -25,7 +25,7 @@ class Meta: } -class Query(object): +class Query: recipe = Node.Field(RecipeNode) all_recipes = DjangoFilterConnectionField(RecipeNode) diff --git a/examples/cookbook/dummy_data.json b/examples/cookbook/dummy_data.json index f541da5f5..c585bfcdf 100644 --- a/examples/cookbook/dummy_data.json +++ b/examples/cookbook/dummy_data.json @@ -1 +1,302 @@ -[{"model": "auth.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$24000$0SgBlSlnbv5c$ijVQipm2aNDlcrTL8Qi3SVNHphTm4HIsDfUi4kn9tog=", "last_login": "2016-11-04T00:46:58Z", "is_superuser": true, "username": "admin", "first_name": "", "last_name": "", "email": "asdf@example.com", "is_staff": true, "is_active": true, "date_joined": "2016-11-03T18:24:40Z", "groups": [], "user_permissions": []}}, {"model": "recipes.recipe", "pk": 1, "fields": {"title": "Cheerios With a Shot of Vermouth", "instructions": "https://xkcd.com/720/"}}, {"model": "recipes.recipe", "pk": 2, "fields": {"title": "Quail Eggs in Whipped Cream and MSG", "instructions": "https://xkcd.com/720/"}}, {"model": "recipes.recipe", "pk": 3, "fields": {"title": "Deep Fried Skittles", "instructions": "https://xkcd.com/720/"}}, {"model": "recipes.recipe", "pk": 4, "fields": {"title": "Newt ala Doritos", "instructions": "https://xkcd.com/720/"}}, {"model": "recipes.recipe", "pk": 5, "fields": {"title": "Fruit Salad", "instructions": "Chop up and add together"}}, {"model": "recipes.recipeingredient", "pk": 1, "fields": {"recipes": 5, "ingredient": 9, "amount": 1.0, "unit": "unit"}}, {"model": "recipes.recipeingredient", "pk": 2, "fields": {"recipes": 5, "ingredient": 10, "amount": 2.0, "unit": "unit"}}, {"model": "recipes.recipeingredient", "pk": 3, "fields": {"recipes": 5, "ingredient": 7, "amount": 3.0, "unit": "unit"}}, {"model": "recipes.recipeingredient", "pk": 4, "fields": {"recipes": 5, "ingredient": 8, "amount": 4.0, "unit": "unit"}}, {"model": "recipes.recipeingredient", "pk": 5, "fields": {"recipes": 4, "ingredient": 5, "amount": 1.0, "unit": "kg"}}, {"model": "recipes.recipeingredient", "pk": 6, "fields": {"recipes": 4, "ingredient": 6, "amount": 2.0, "unit": "l"}}, {"model": "recipes.recipeingredient", "pk": 7, "fields": {"recipes": 3, "ingredient": 4, "amount": 1.0, "unit": "unit"}}, {"model": "recipes.recipeingredient", "pk": 8, "fields": {"recipes": 2, "ingredient": 2, "amount": 1.0, "unit": "kg"}}, {"model": "recipes.recipeingredient", "pk": 9, "fields": {"recipes": 2, "ingredient": 11, "amount": 2.0, "unit": "l"}}, {"model": "recipes.recipeingredient", "pk": 10, "fields": {"recipes": 2, "ingredient": 12, "amount": 3.0, "unit": "st"}}, {"model": "recipes.recipeingredient", "pk": 11, "fields": {"recipes": 1, "ingredient": 1, "amount": 1.0, "unit": "kg"}}, {"model": "recipes.recipeingredient", "pk": 12, "fields": {"recipes": 1, "ingredient": 3, "amount": 1.0, "unit": "st"}}, {"model": "ingredients.category", "pk": 1, "fields": {"name": "fruit"}}, {"model": "ingredients.category", "pk": 3, "fields": {"name": "xkcd"}}, {"model": "ingredients.ingredient", "pk": 1, "fields": {"name": "Cheerios", "notes": "this is a note", "category": 3}}, {"model": "ingredients.ingredient", "pk": 2, "fields": {"name": "Quail Eggs", "notes": "has more notes", "category": 3}}, {"model": "ingredients.ingredient", "pk": 3, "fields": {"name": "Vermouth", "notes": "", "category": 3}}, {"model": "ingredients.ingredient", "pk": 4, "fields": {"name": "Skittles", "notes": "", "category": 3}}, {"model": "ingredients.ingredient", "pk": 5, "fields": {"name": "Newt", "notes": "Braised and Confuesd", "category": 3}}, {"model": "ingredients.ingredient", "pk": 6, "fields": {"name": "Doritos", "notes": "Crushed", "category": 3}}, {"model": "ingredients.ingredient", "pk": 7, "fields": {"name": "Apple", "notes": "", "category": 1}}, {"model": "ingredients.ingredient", "pk": 8, "fields": {"name": "Orange", "notes": "", "category": 1}}, {"model": "ingredients.ingredient", "pk": 9, "fields": {"name": "Banana", "notes": "", "category": 1}}, {"model": "ingredients.ingredient", "pk": 10, "fields": {"name": "Grapes", "notes": "", "category": 1}}, {"model": "ingredients.ingredient", "pk": 11, "fields": {"name": "Whipped Cream", "notes": "", "category": 3}}, {"model": "ingredients.ingredient", "pk": 12, "fields": {"name": "MSG", "notes": "", "category": 3}}] \ No newline at end of file +[ + { + "fields": { + "date_joined": "2016-11-03T18:24:40Z", + "email": "asdf@example.com", + "first_name": "", + "groups": [], + "is_active": true, + "is_staff": true, + "is_superuser": true, + "last_login": "2016-11-04T00:46:58Z", + "last_name": "", + "password": "pbkdf2_sha256$24000$0SgBlSlnbv5c$ijVQipm2aNDlcrTL8Qi3SVNHphTm4HIsDfUi4kn9tog=", + "user_permissions": [], + "username": "admin" + }, + "model": "auth.user", + "pk": 1 + }, + { + "fields": { + "instructions": "https://xkcd.com/720/", + "title": "Cheerios With a Shot of Vermouth" + }, + "model": "recipes.recipe", + "pk": 1 + }, + { + "fields": { + "instructions": "https://xkcd.com/720/", + "title": "Quail Eggs in Whipped Cream and MSG" + }, + "model": "recipes.recipe", + "pk": 2 + }, + { + "fields": { + "instructions": "https://xkcd.com/720/", + "title": "Deep Fried Skittles" + }, + "model": "recipes.recipe", + "pk": 3 + }, + { + "fields": { + "instructions": "https://xkcd.com/720/", + "title": "Newt ala Doritos" + }, + "model": "recipes.recipe", + "pk": 4 + }, + { + "fields": { + "instructions": "Chop up and add together", + "title": "Fruit Salad" + }, + "model": "recipes.recipe", + "pk": 5 + }, + { + "fields": { + "amount": 1.0, + "ingredient": 9, + "recipes": 5, + "unit": "unit" + }, + "model": "recipes.recipeingredient", + "pk": 1 + }, + { + "fields": { + "amount": 2.0, + "ingredient": 10, + "recipes": 5, + "unit": "unit" + }, + "model": "recipes.recipeingredient", + "pk": 2 + }, + { + "fields": { + "amount": 3.0, + "ingredient": 7, + "recipes": 5, + "unit": "unit" + }, + "model": "recipes.recipeingredient", + "pk": 3 + }, + { + "fields": { + "amount": 4.0, + "ingredient": 8, + "recipes": 5, + "unit": "unit" + }, + "model": "recipes.recipeingredient", + "pk": 4 + }, + { + "fields": { + "amount": 1.0, + "ingredient": 5, + "recipes": 4, + "unit": "kg" + }, + "model": "recipes.recipeingredient", + "pk": 5 + }, + { + "fields": { + "amount": 2.0, + "ingredient": 6, + "recipes": 4, + "unit": "l" + }, + "model": "recipes.recipeingredient", + "pk": 6 + }, + { + "fields": { + "amount": 1.0, + "ingredient": 4, + "recipes": 3, + "unit": "unit" + }, + "model": "recipes.recipeingredient", + "pk": 7 + }, + { + "fields": { + "amount": 1.0, + "ingredient": 2, + "recipes": 2, + "unit": "kg" + }, + "model": "recipes.recipeingredient", + "pk": 8 + }, + { + "fields": { + "amount": 2.0, + "ingredient": 11, + "recipes": 2, + "unit": "l" + }, + "model": "recipes.recipeingredient", + "pk": 9 + }, + { + "fields": { + "amount": 3.0, + "ingredient": 12, + "recipes": 2, + "unit": "st" + }, + "model": "recipes.recipeingredient", + "pk": 10 + }, + { + "fields": { + "amount": 1.0, + "ingredient": 1, + "recipes": 1, + "unit": "kg" + }, + "model": "recipes.recipeingredient", + "pk": 11 + }, + { + "fields": { + "amount": 1.0, + "ingredient": 3, + "recipes": 1, + "unit": "st" + }, + "model": "recipes.recipeingredient", + "pk": 12 + }, + { + "fields": { + "name": "fruit" + }, + "model": "ingredients.category", + "pk": 1 + }, + { + "fields": { + "name": "xkcd" + }, + "model": "ingredients.category", + "pk": 3 + }, + { + "fields": { + "category": 3, + "name": "Cheerios", + "notes": "this is a note" + }, + "model": "ingredients.ingredient", + "pk": 1 + }, + { + "fields": { + "category": 3, + "name": "Quail Eggs", + "notes": "has more notes" + }, + "model": "ingredients.ingredient", + "pk": 2 + }, + { + "fields": { + "category": 3, + "name": "Vermouth", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 3 + }, + { + "fields": { + "category": 3, + "name": "Skittles", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 4 + }, + { + "fields": { + "category": 3, + "name": "Newt", + "notes": "Braised and Confuesd" + }, + "model": "ingredients.ingredient", + "pk": 5 + }, + { + "fields": { + "category": 3, + "name": "Doritos", + "notes": "Crushed" + }, + "model": "ingredients.ingredient", + "pk": 6 + }, + { + "fields": { + "category": 1, + "name": "Apple", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 7 + }, + { + "fields": { + "category": 1, + "name": "Orange", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 8 + }, + { + "fields": { + "category": 1, + "name": "Banana", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 9 + }, + { + "fields": { + "category": 1, + "name": "Grapes", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 10 + }, + { + "fields": { + "category": 3, + "name": "Whipped Cream", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 11 + }, + { + "fields": { + "category": 3, + "name": "MSG", + "notes": "" + }, + "model": "ingredients.ingredient", + "pk": 12 + } +] diff --git a/examples/starwars/models.py b/examples/starwars/models.py index 03e06a292..fb76b0395 100644 --- a/examples/starwars/models.py +++ b/examples/starwars/models.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - from django.db import models diff --git a/graphene_django/compat.py b/graphene_django/compat.py index 195678610..b0e475357 100644 --- a/graphene_django/compat.py +++ b/graphene_django/compat.py @@ -1,4 +1,4 @@ -class MissingType(object): +class MissingType: def __init__(self, *args, **kwargs): pass diff --git a/graphene_django/converter.py b/graphene_django/converter.py index 338ab6de4..acd483bd8 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -68,8 +68,7 @@ def get_choices(choices): choices = choices.items() for value, help_text in choices: if isinstance(help_text, (tuple, list)): - for choice in get_choices(help_text): - yield choice + yield from get_choices(help_text) else: name = convert_choice_name(value) while name in converted_names: @@ -86,7 +85,7 @@ def convert_choices_to_named_enum_with_descriptions(name, choices): named_choices = [(c[0], c[1]) for c in choices] named_choices_descriptions = {c[0]: c[2] for c in choices} - class EnumWithDescriptionsType(object): + class EnumWithDescriptionsType: @property def description(self): return str(named_choices_descriptions[self.name]) @@ -103,7 +102,7 @@ def generate_enum_name(django_model_meta, field): ) name = custom_func(field) elif graphene_settings.DJANGO_CHOICE_FIELD_ENUM_V2_NAMING is True: - name = to_camel_case("{}_{}".format(django_model_meta.object_name, field.name)) + name = to_camel_case(f"{django_model_meta.object_name}_{field.name}") else: name = "{app_label}{object_name}{field_name}Choices".format( app_label=to_camel_case(django_model_meta.app_label.title()), @@ -149,7 +148,9 @@ def get_django_field_description(field): @singledispatch def convert_django_field(field, registry=None): raise Exception( - "Don't know how to convert the Django field %s (%s)" % (field, field.__class__) + "Don't know how to convert the Django field {} ({})".format( + field, field.__class__ + ) ) diff --git a/graphene_django/debug/middleware.py b/graphene_django/debug/middleware.py index 804e7c838..5b9d82e8d 100644 --- a/graphene_django/debug/middleware.py +++ b/graphene_django/debug/middleware.py @@ -7,7 +7,7 @@ from .types import DjangoDebug -class DjangoDebugContext(object): +class DjangoDebugContext: def __init__(self): self.debug_promise = None self.promises = [] @@ -46,7 +46,7 @@ def disable_instrumentation(self): unwrap_cursor(connection) -class DjangoDebugMiddleware(object): +class DjangoDebugMiddleware: def resolve(self, next, root, info, **args): context = info.context django_debug = getattr(context, "django_debug", None) diff --git a/graphene_django/debug/sql/tracking.py b/graphene_django/debug/sql/tracking.py index f7346e642..bf0ea367f 100644 --- a/graphene_django/debug/sql/tracking.py +++ b/graphene_django/debug/sql/tracking.py @@ -1,5 +1,4 @@ # Code obtained from django-debug-toolbar sql panel tracking -from __future__ import absolute_import, unicode_literals import json from threading import local @@ -50,7 +49,7 @@ def unwrap_cursor(connection): del connection._graphene_cursor -class ExceptionCursorWrapper(object): +class ExceptionCursorWrapper: """ Wraps a cursor and raises an exception on any operation. Used in Templates panel. @@ -63,7 +62,7 @@ def __getattr__(self, attr): raise SQLQueryTriggered() -class NormalCursorWrapper(object): +class NormalCursorWrapper: """ Wraps a cursor and logs queries. """ @@ -85,7 +84,7 @@ def _quote_params(self, params): if not params: return params if isinstance(params, dict): - return dict((key, self._quote_expr(value)) for key, value in params.items()) + return {key: self._quote_expr(value) for key, value in params.items()} return list(map(self._quote_expr, params)) def _decode(self, param): diff --git a/graphene_django/debug/tests/test_query.py b/graphene_django/debug/tests/test_query.py index eae94dcd4..1ea86b123 100644 --- a/graphene_django/debug/tests/test_query.py +++ b/graphene_django/debug/tests/test_query.py @@ -8,7 +8,7 @@ from ..types import DjangoDebug -class context(object): +class context: pass diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 05a701063..0fe123deb 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -28,7 +28,7 @@ def __init__(self, _type, *args, **kwargs): _type = _type.of_type # Django would never return a Set of None vvvvvvv - super(DjangoListField, self).__init__(List(NonNull(_type)), *args, **kwargs) + super().__init__(List(NonNull(_type)), *args, **kwargs) assert issubclass( self._underlying_type, DjangoObjectType @@ -63,7 +63,7 @@ def list_resolver( return queryset def wrap_resolve(self, parent_resolver): - resolver = super(DjangoListField, self).wrap_resolve(parent_resolver) + resolver = super().wrap_resolve(parent_resolver) _type = self.type if isinstance(_type, NonNull): _type = _type.of_type @@ -87,7 +87,7 @@ def __init__(self, *args, **kwargs): graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST, ) kwargs.setdefault("offset", Int()) - super(DjangoConnectionField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @property def type(self): diff --git a/graphene_django/filter/fields.py b/graphene_django/filter/fields.py index eeb197ed5..cdb8f850f 100644 --- a/graphene_django/filter/fields.py +++ b/graphene_django/filter/fields.py @@ -44,7 +44,7 @@ def __init__( self._filtering_args = None self._extra_filter_meta = extra_filter_meta self._base_args = None - super(DjangoFilterConnectionField, self).__init__(type_, *args, **kwargs) + super().__init__(type_, *args, **kwargs) @property def args(self): @@ -90,9 +90,7 @@ def filter_kwargs(): kwargs[k] = convert_enum(v) return kwargs - qs = super(DjangoFilterConnectionField, cls).resolve_queryset( - connection, iterable, info, args - ) + qs = super().resolve_queryset(connection, iterable, info, args) filterset = filterset_class( data=filter_kwargs(), queryset=qs, request=info.context diff --git a/graphene_django/filter/filters/array_filter.py b/graphene_django/filter/filters/array_filter.py index e886cff97..b6f4808ec 100644 --- a/graphene_django/filter/filters/array_filter.py +++ b/graphene_django/filter/filters/array_filter.py @@ -22,6 +22,6 @@ def filter(self, qs, value): return qs if self.distinct: qs = qs.distinct() - lookup = "%s__%s" % (self.field_name, self.lookup_expr) + lookup = f"{self.field_name}__{self.lookup_expr}" qs = self.get_method(qs)(**{lookup: value}) return qs diff --git a/graphene_django/filter/filters/global_id_filter.py b/graphene_django/filter/filters/global_id_filter.py index da16585ee..37877d58b 100644 --- a/graphene_django/filter/filters/global_id_filter.py +++ b/graphene_django/filter/filters/global_id_filter.py @@ -17,7 +17,7 @@ def filter(self, qs, value): _id = None if value is not None: _, _id = from_global_id(value) - return super(GlobalIDFilter, self).filter(qs, _id) + return super().filter(qs, _id) class GlobalIDMultipleChoiceFilter(MultipleChoiceFilter): @@ -25,4 +25,4 @@ class GlobalIDMultipleChoiceFilter(MultipleChoiceFilter): def filter(self, qs, value): gids = [from_global_id(v)[1] for v in value] - return super(GlobalIDMultipleChoiceFilter, self).filter(qs, gids) + return super().filter(qs, gids) diff --git a/graphene_django/filter/filters/list_filter.py b/graphene_django/filter/filters/list_filter.py index 9689be3f1..6689877cb 100644 --- a/graphene_django/filter/filters/list_filter.py +++ b/graphene_django/filter/filters/list_filter.py @@ -23,4 +23,4 @@ def filter(self, qs, value): else: return qs.none() else: - return super(ListFilter, self).filter(qs, value) + return super().filter(qs, value) diff --git a/graphene_django/filter/filters/typed_filter.py b/graphene_django/filter/filters/typed_filter.py index 2c813e4c6..76f903aea 100644 --- a/graphene_django/filter/filters/typed_filter.py +++ b/graphene_django/filter/filters/typed_filter.py @@ -12,7 +12,7 @@ class TypedFilter(Filter): def __init__(self, input_type=None, *args, **kwargs): self._input_type = input_type - super(TypedFilter, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @property def input_type(self): diff --git a/graphene_django/filter/filterset.py b/graphene_django/filter/filterset.py index 57c35aff8..fa91477f1 100644 --- a/graphene_django/filter/filterset.py +++ b/graphene_django/filter/filterset.py @@ -31,7 +31,7 @@ class GrapheneFilterSetMixin(BaseFilterSet): def setup_filterset(filterset_class): """Wrap a provided filterset in Graphene-specific functionality""" return type( - "Graphene{}".format(filterset_class.__name__), + f"Graphene{filterset_class.__name__}", (filterset_class, GrapheneFilterSetMixin), {}, ) @@ -40,7 +40,7 @@ def setup_filterset(filterset_class): def custom_filterset_factory(model, filterset_base_class=FilterSet, **meta): """Create a filterset for the given model using the provided meta data""" meta.update({"model": model}) - meta_class = type(str("Meta"), (object,), meta) + meta_class = type("Meta", (object,), meta) filterset = type( str("%sFilterSet" % model._meta.object_name), (filterset_base_class, GrapheneFilterSetMixin), diff --git a/graphene_django/filter/tests/conftest.py b/graphene_django/filter/tests/conftest.py index e2bba68d6..a11831c96 100644 --- a/graphene_django/filter/tests/conftest.py +++ b/graphene_django/filter/tests/conftest.py @@ -1,4 +1,4 @@ -from mock import MagicMock +from unittest.mock import MagicMock import pytest from django.db import models diff --git a/graphene_django/filter/tests/test_fields.py b/graphene_django/filter/tests/test_fields.py index fe4ae8797..bee3c6cf4 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -67,7 +67,7 @@ def assert_arguments(field, *arguments): actual = [name for name in args if name not in ignore and not name.startswith("_")] assert set(arguments) == set( actual - ), "Expected arguments ({}) did not match actual ({})".format(arguments, actual) + ), f"Expected arguments ({arguments}) did not match actual ({actual})" def assert_orderable(field): @@ -141,7 +141,7 @@ class Meta: @property def qs(self): - qs = super(ArticleContextFilter, self).qs + qs = super().qs return qs.filter(reporter=self.request.reporter) class Query(ObjectType): @@ -166,7 +166,7 @@ class Query(ObjectType): editor=r2, ) - class context(object): + class context: reporter = r2 query = """ diff --git a/graphene_django/filter/tests/test_in_filter.py b/graphene_django/filter/tests/test_in_filter.py index 7ad0286ac..a69d6f5e4 100644 --- a/graphene_django/filter/tests/test_in_filter.py +++ b/graphene_django/filter/tests/test_in_filter.py @@ -349,19 +349,19 @@ def test_fk_id_in_filter(query): schema = Schema(query=query) query = """ - query { - articles (reporter_In: [%s, %s]) { - edges { - node { + query {{ + articles (reporter_In: [{}, {}]) {{ + edges {{ + node {{ headline - reporter { + reporter {{ lastName - } - } - } - } - } - """ % ( + }} + }} + }} + }} + }} + """.format( john_doe.id, jean_bon.id, ) diff --git a/graphene_django/filter/tests/test_typed_filter.py b/graphene_django/filter/tests/test_typed_filter.py index a7edc5698..f22138ff2 100644 --- a/graphene_django/filter/tests/test_typed_filter.py +++ b/graphene_django/filter/tests/test_typed_filter.py @@ -98,7 +98,7 @@ def test_typed_filter_schema(schema): ) for filter_field, gql_type in filters.items(): - assert "{}: {}".format(filter_field, gql_type) in all_articles_filters + assert f"{filter_field}: {gql_type}" in all_articles_filters def test_typed_filters_work(schema): diff --git a/graphene_django/forms/mutation.py b/graphene_django/forms/mutation.py index 13e9863d7..3d5946409 100644 --- a/graphene_django/forms/mutation.py +++ b/graphene_django/forms/mutation.py @@ -95,7 +95,7 @@ def __init_subclass_with_meta__( _meta.fields = yank_fields_from_attrs(output_fields, _as=Field) input_fields = yank_fields_from_attrs(input_fields, _as=InputField) - super(DjangoFormMutation, cls).__init_subclass_with_meta__( + super().__init_subclass_with_meta__( _meta=_meta, input_fields=input_fields, **options ) @@ -127,7 +127,7 @@ def __init_subclass_with_meta__( return_field_name=None, only_fields=(), exclude_fields=(), - **options + **options, ): if not form_class: @@ -147,7 +147,7 @@ def __init_subclass_with_meta__( registry = get_global_registry() model_type = registry.get_type_for_model(model) if not model_type: - raise Exception("No type registered for model: {}".format(model.__name__)) + raise Exception(f"No type registered for model: {model.__name__}") if not return_field_name: model_name = model.__name__ @@ -163,7 +163,7 @@ def __init_subclass_with_meta__( _meta.fields = yank_fields_from_attrs(output_fields, _as=Field) input_fields = yank_fields_from_attrs(input_fields, _as=InputField) - super(DjangoModelFormMutation, cls).__init_subclass_with_meta__( + super().__init_subclass_with_meta__( _meta=_meta, input_fields=input_fields, **options ) diff --git a/graphene_django/management/commands/graphql_schema.py b/graphene_django/management/commands/graphql_schema.py index 41654305f..bedddbac5 100644 --- a/graphene_django/management/commands/graphql_schema.py +++ b/graphene_django/management/commands/graphql_schema.py @@ -73,16 +73,12 @@ def get_schema(self, schema, out, indent): elif file_extension == ".json": self.save_json_file(out, schema_dict, indent) else: - raise CommandError( - 'Unrecognised file format "{}"'.format(file_extension) - ) + raise CommandError(f'Unrecognised file format "{file_extension}"') style = getattr(self, "style", None) success = getattr(style, "SUCCESS", lambda x: x) - self.stdout.write( - success("Successfully dumped GraphQL schema to {}".format(out)) - ) + self.stdout.write(success(f"Successfully dumped GraphQL schema to {out}")) def handle(self, *args, **options): options_schema = options.get("schema") diff --git a/graphene_django/registry.py b/graphene_django/registry.py index 50a8ae510..470863779 100644 --- a/graphene_django/registry.py +++ b/graphene_django/registry.py @@ -1,4 +1,4 @@ -class Registry(object): +class Registry: def __init__(self): self._registry = {} self._field_registry = {} diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 000b21e18..c01d915fa 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -114,7 +114,7 @@ def __init_subclass_with_meta__( _meta.fields = yank_fields_from_attrs(output_fields, _as=Field) input_fields = yank_fields_from_attrs(input_fields, _as=InputField) - super(SerializerMutation, cls).__init_subclass_with_meta__( + super().__init_subclass_with_meta__( _meta=_meta, input_fields=input_fields, **options ) diff --git a/graphene_django/rest_framework/serializer_converter.py b/graphene_django/rest_framework/serializer_converter.py index 9835475d3..1d850f031 100644 --- a/graphene_django/rest_framework/serializer_converter.py +++ b/graphene_django/rest_framework/serializer_converter.py @@ -72,7 +72,7 @@ def convert_serializer_to_input_type(serializer_class): for name, field in serializer.fields.items() } ret_type = type( - "{}Input".format(serializer.__class__.__name__), + f"{serializer.__class__.__name__}Input", (graphene.InputObjectType,), items, ) diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 0fd70a721..7dcea06bd 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -11,7 +11,6 @@ Graphene settings, checking for user settings first, then falling back to the defaults. """ -from __future__ import unicode_literals from django.conf import settings from django.test.signals import setting_changed @@ -77,7 +76,7 @@ def import_from_string(val, setting_name): module = importlib.import_module(module_path) return getattr(module, class_name) except (ImportError, AttributeError) as e: - msg = "Could not import '%s' for Graphene setting '%s'. %s: %s." % ( + msg = "Could not import '{}' for Graphene setting '{}'. {}: {}.".format( val, setting_name, e.__class__.__name__, @@ -86,7 +85,7 @@ def import_from_string(val, setting_name): raise ImportError(msg) -class GrapheneSettings(object): +class GrapheneSettings: """ A settings object, that allows API settings to be accessed as properties. For example: diff --git a/graphene_django/tests/models.py b/graphene_django/tests/models.py index c26a6d8d5..636f74c6d 100644 --- a/graphene_django/tests/models.py +++ b/graphene_django/tests/models.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - from django.db import models from django.utils.translation import gettext_lazy as _ @@ -37,7 +35,7 @@ class Film(models.Model): class DoeReporterManager(models.Manager): def get_queryset(self): - return super(DoeReporterManager, self).get_queryset().filter(last_name="Doe") + return super().get_queryset().filter(last_name="Doe") class Reporter(models.Model): @@ -57,7 +55,7 @@ class Reporter(models.Model): ) def __str__(self): # __unicode__ on Python 2 - return "%s %s" % (self.first_name, self.last_name) + return f"{self.first_name} {self.last_name}" def __init__(self, *args, **kwargs): """ @@ -67,7 +65,7 @@ def __init__(self, *args, **kwargs): when a CNNReporter is pulled from the database, it is still of type Reporter. This was added to test proxy model support. """ - super(Reporter, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) if self.reporter_type == 2: # quick and dirty way without enums self.__class__ = CNNReporter @@ -77,7 +75,7 @@ def some_method(self): class CNNReporterManager(models.Manager): def get_queryset(self): - return super(CNNReporterManager, self).get_queryset().filter(reporter_type=2) + return super().get_queryset().filter(reporter_type=2) class CNNReporter(Reporter): diff --git a/graphene_django/tests/test_command.py b/graphene_django/tests/test_command.py index 11a15bc6f..a281abbd2 100644 --- a/graphene_django/tests/test_command.py +++ b/graphene_django/tests/test_command.py @@ -2,7 +2,7 @@ from django.core import management from io import StringIO -from mock import mock_open, patch +from unittest.mock import mock_open, patch from graphene import ObjectType, Schema, String diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index e6ae64f56..504bb0e92 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1151,9 +1151,9 @@ class Query(graphene.ObjectType): REPORTERS = [ dict( - first_name="First {}".format(i), - last_name="Last {}".format(i), - email="johndoe+{}@example.com".format(i), + first_name=f"First {i}", + last_name=f"Last {i}", + email=f"johndoe+{i}@example.com", a_choice=1, ) for i in range(6) diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 4885917b0..fad26e2ab 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -3,7 +3,7 @@ import pytest from django.db import models -from mock import patch +from unittest.mock import patch from graphene import Connection, Field, Interface, ObjectType, Schema, String from graphene.relay import Node @@ -104,7 +104,7 @@ class Meta: @classmethod def __init_subclass_with_meta__(cls, **options): options.setdefault("_meta", ArticleTypeOptions(cls)) - super(ArticleType, cls).__init_subclass_with_meta__(**options) + super().__init_subclass_with_meta__(**options) class Article(ArticleType): class Meta: @@ -484,7 +484,7 @@ class Meta: def custom_enum_name(field): - return "CustomEnum{}".format(field.name.title()) + return f"CustomEnum{field.name.title()}" class TestDjangoObjectType: diff --git a/graphene_django/tests/test_utils.py b/graphene_django/tests/test_utils.py index adad00efa..5958a8c32 100644 --- a/graphene_django/tests/test_utils.py +++ b/graphene_django/tests/test_utils.py @@ -2,7 +2,7 @@ import pytest from django.utils.translation import gettext_lazy -from mock import patch +from unittest.mock import patch from ..utils import camelize, get_model_fields, GraphQLTestCase from .models import Film, Reporter @@ -11,11 +11,11 @@ def test_get_model_fields_no_duplication(): reporter_fields = get_model_fields(Reporter) - reporter_name_set = set([field[0] for field in reporter_fields]) + reporter_name_set = {field[0] for field in reporter_fields} assert len(reporter_fields) == len(reporter_name_set) film_fields = get_model_fields(Film) - film_name_set = set([field[0] for field in film_fields]) + film_name_set = {field[0] for field in film_fields} assert len(film_fields) == len(film_name_set) diff --git a/graphene_django/tests/test_views.py b/graphene_django/tests/test_views.py index c2f18c34c..5cadefe7e 100644 --- a/graphene_django/tests/test_views.py +++ b/graphene_django/tests/test_views.py @@ -2,7 +2,7 @@ import pytest -from mock import patch +from unittest.mock import patch from django.db import connection @@ -507,7 +507,7 @@ def test_handles_invalid_json_bodies(client): def test_handles_django_request_error(client, monkeypatch): def mocked_read(*args): - raise IOError("foo-bar") + raise OSError("foo-bar") monkeypatch.setattr("django.http.request.HttpRequest.read", mocked_read) diff --git a/graphene_django/types.py b/graphene_django/types.py index 0ebb7d301..a6e54af41 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -168,10 +168,8 @@ def __init_subclass_with_meta__( if not DJANGO_FILTER_INSTALLED and (filter_fields or filterset_class): raise Exception( - ( - "Can only set filter_fields or filterset_class if " - "Django-Filter is installed" - ) + "Can only set filter_fields or filterset_class if " + "Django-Filter is installed" ) assert not (fields and exclude), ( @@ -228,7 +226,7 @@ def __init_subclass_with_meta__( if use_connection is None and interfaces: use_connection = any( - (issubclass(interface, Node) for interface in interfaces) + issubclass(interface, Node) for interface in interfaces ) if use_connection and not connection: @@ -255,7 +253,7 @@ def __init_subclass_with_meta__( _meta.fields = django_fields _meta.connection = connection - super(DjangoObjectType, cls).__init_subclass_with_meta__( + super().__init_subclass_with_meta__( _meta=_meta, interfaces=interfaces, **options ) diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index f94c38574..be59ba819 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -63,7 +63,7 @@ def graphql_query( return resp -class GraphQLTestMixin(object): +class GraphQLTestMixin: """ Based on: https://www.sam.today/blog/testing-graphql-with-graphene-django/ """ diff --git a/graphene_django/views.py b/graphene_django/views.py index bf333a96e..e772d53b6 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -26,7 +26,7 @@ class HttpError(Exception): def __init__(self, response, message=None, *args, **kwargs): self.response = response self.message = message = message or response.content.decode() - super(HttpError, self).__init__(message, *args, **kwargs) + super().__init__(message, *args, **kwargs) def get_accepted_content_types(request):