Skip to content

Commit f068c27

Browse files
committed
fix: black format errors
1 parent b59133c commit f068c27

File tree

5 files changed

+69
-45
lines changed

5 files changed

+69
-45
lines changed

graphene_pydantic/converters.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@
1010
from types import UnionType
1111

1212
import graphene
13-
from graphene import (Boolean, Enum, Field, Float, ID, InputField, Int, JSONString, List, String, UUID, Union)
13+
from graphene import (
14+
Boolean,
15+
Enum,
16+
Field,
17+
Float,
18+
ID,
19+
InputField,
20+
Int,
21+
JSONString,
22+
List,
23+
String,
24+
UUID,
25+
Union,
26+
)
1427
from graphene.types.base import BaseType
1528
from graphene.types.datetime import Date, DateTime, Time
1629
from pydantic import BaseModel
@@ -24,6 +37,7 @@
2437

2538
try:
2639
from bson import ObjectId
40+
2741
BSON_OBJECT_ID_SUPPORTED = True
2842
except ImportError:
2943
BSON_OBJECT_ID_SUPPORTED = False
@@ -74,7 +88,9 @@ def convert_pydantic_input_field(
7488
),
7589
)
7690
field_kwargs.setdefault("required", field.is_required())
77-
field_kwargs.setdefault("default_value", None if field.default is PydanticUndefined else field.default)
91+
field_kwargs.setdefault(
92+
"default_value", None if field.default is PydanticUndefined else field.default
93+
)
7894
# TODO: find a better way to get a field's description. Some ideas include:
7995
# - hunt down the description from the field's schema, or the schema
8096
# from the field's base model
@@ -292,13 +308,13 @@ def convert_generic_python_type(
292308
type_, field, registry, parent_type=parent_type, model=model
293309
)
294310
elif origin in (
295-
T.Tuple,
296-
T.List,
297-
T.Set,
298-
T.Collection,
299-
T.Iterable,
300-
list,
301-
set,
311+
T.Tuple,
312+
T.List,
313+
T.Set,
314+
T.Collection,
315+
T.Iterable,
316+
list,
317+
set,
302318
) or issubclass(origin, collections.abc.Sequence):
303319
# TODO: find a better way of divining that the origin is sequence-like
304320
inner_types = getattr(type_, "__args__", [])
@@ -315,7 +331,7 @@ def convert_generic_python_type(
315331
)
316332
)
317333
elif origin in (T.Dict, T.Mapping, collections.OrderedDict, dict) or issubclass(
318-
origin, collections.abc.Mapping
334+
origin, collections.abc.Mapping
319335
):
320336
raise ConversionError("Don't know how to handle mappings in Graphene.")
321337
else:

graphene_pydantic/inputobjecttype.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class PydanticInputObjectTypeOptions(InputObjectTypeOptions):
2020

2121

2222
def construct_fields(
23-
obj_type: T.Type["PydanticInputObjectType"],
24-
model: T.Type[pydantic.BaseModel],
25-
registry: Registry,
26-
only_fields: T.Tuple[str, ...],
27-
exclude_fields: T.Tuple[str, ...],
23+
obj_type: T.Type["PydanticInputObjectType"],
24+
model: T.Type[pydantic.BaseModel],
25+
registry: Registry,
26+
only_fields: T.Tuple[str, ...],
27+
exclude_fields: T.Tuple[str, ...],
2828
) -> T.Dict[str, InputField]:
2929
"""
3030
Construct all the fields for a PydanticInputObjectType.
@@ -45,7 +45,6 @@ def construct_fields(
4545

4646
fields = {}
4747
for name, field in fields_to_convert:
48-
4948
# Graphql does not accept union as input. Refer https://github.com/graphql/graphql-spec/issues/488
5049
if isinstance(getattr(field, "annotation", None), UnionType):
5150
union_types = field.annotation.__args__
@@ -71,15 +70,15 @@ class PydanticInputObjectType(graphene.InputObjectType):
7170

7271
@classmethod
7372
def __init_subclass_with_meta__(
74-
cls,
75-
model: type = None,
76-
registry: Registry = None,
77-
skip_registry: bool = False,
78-
only_fields: T.Tuple[str, ...] = (),
79-
exclude_fields: T.Tuple[str, ...] = (),
80-
id=None,
81-
_meta=None,
82-
**options,
73+
cls,
74+
model: type = None,
75+
registry: Registry = None,
76+
skip_registry: bool = False,
77+
only_fields: T.Tuple[str, ...] = (),
78+
exclude_fields: T.Tuple[str, ...] = (),
79+
id=None,
80+
_meta=None,
81+
**options,
8382
):
8483
assert model and issubclass(
8584
model, pydantic.BaseModel

graphene_pydantic/objecttype.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class PydanticObjectTypeOptions(ObjectTypeOptions):
2020

2121

2222
def construct_fields(
23-
obj_type: T.Type["PydanticObjectType"],
24-
model: T.Type[pydantic.BaseModel],
25-
registry: Registry,
26-
only_fields: T.Tuple[str, ...],
27-
exclude_fields: T.Tuple[str, ...],
23+
obj_type: T.Type["PydanticObjectType"],
24+
model: T.Type[pydantic.BaseModel],
25+
registry: Registry,
26+
only_fields: T.Tuple[str, ...],
27+
exclude_fields: T.Tuple[str, ...],
2828
) -> T.Dict[str, graphene.Field]:
2929
"""
3030
Construct all the fields for a PydanticObjectType.
@@ -61,16 +61,16 @@ class PydanticObjectType(graphene.ObjectType):
6161

6262
@classmethod
6363
def __init_subclass_with_meta__(
64-
cls,
65-
model: type = None,
66-
registry: Registry = None,
67-
skip_registry: bool = False,
68-
only_fields: T.Tuple[str, ...] = (),
69-
exclude_fields: T.Tuple[str, ...] = (),
70-
interfaces=(),
71-
id=None,
72-
_meta=None,
73-
**options,
64+
cls,
65+
model: type = None,
66+
registry: Registry = None,
67+
skip_registry: bool = False,
68+
only_fields: T.Tuple[str, ...] = (),
69+
exclude_fields: T.Tuple[str, ...] = (),
70+
interfaces=(),
71+
id=None,
72+
_meta=None,
73+
**options,
7474
):
7575
assert model and issubclass(
7676
model, pydantic.BaseModel

tests/test_converters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def test_literal():
8989
assert field.default_value == 3
9090
assert field.type.of_type.__name__.startswith("UnionOf")
9191

92-
9392
def test_literal_singleton():
9493
field = _convert_field_from_spec("attr", (T.Literal["literal1"], "literal1"))
9594
assert issubclass(field.type.of_type, graphene.String)
@@ -165,7 +164,9 @@ class Meta:
165164

166165
def test_unresolved_placeholders():
167166
# no errors should be raised here -- instead a placeholder is created
168-
field = _convert_field_from_spec("attr", (create_model("Model", size=(int, ...)), None))
167+
field = _convert_field_from_spec(
168+
"attr", (create_model("Model", size=(int, ...)), None)
169+
)
169170
assert type(field.type.of_type) is Placeholder
170171
assert any(
171172
isinstance(x, Placeholder)

tests/test_graphene.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ def test_query():
7575

7676
assert result.errors is None
7777
assert result.data is not None
78-
assert TypeAdapter(List[FooBar]).validate_python(result.data["listFooBars"]) == foo_bars
78+
assert (
79+
TypeAdapter(List[FooBar]).validate_python(result.data["listFooBars"])
80+
== foo_bars
81+
)
7982

8083

8184
def test_query_with_match():
@@ -95,7 +98,10 @@ def test_query_with_match():
9598

9699
assert result.errors is None
97100
assert result.data is not None
98-
assert TypeAdapter(List[FooBar]).validate_python(result.data["listFooBars"]) == foo_bars
101+
assert (
102+
TypeAdapter(List[FooBar]).validate_python(result.data["listFooBars"])
103+
== foo_bars
104+
)
99105

100106

101107
def test_mutation():
@@ -120,4 +126,6 @@ def test_mutation():
120126
assert result.errors is None
121127
assert result.data is not None
122128
assert foo_bars[0] == new_foo_bar
123-
assert TypeAdapter(FooBar).validate_python(result.data["createFooBar"]) == new_foo_bar
129+
assert (
130+
TypeAdapter(FooBar).validate_python(result.data["createFooBar"]) == new_foo_bar
131+
)

0 commit comments

Comments
 (0)