Skip to content

Commit 9bf07dc

Browse files
committed
refactor: rename value_equals to column_type_eq
Signed-off-by: Erik Wrede <erikwrede2@gmail.com>
1 parent 233ece6 commit 9bf07dc

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

graphene_sqlalchemy/converter.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
from .resolvers import get_attr_resolver, get_custom_resolver
2121
from .utils import (
2222
DummyImport,
23+
column_type_eq,
2324
registry_sqlalchemy_model_from_str,
2425
safe_isinstance,
2526
singledispatchbymatchfunction,
26-
value_equals,
2727
)
2828

2929
# We just use MapperProperties for type hints, they don't exist in sqlalchemy < 1.4
@@ -253,61 +253,61 @@ def convert_sqlalchemy_type(
253253
)
254254

255255

256-
@convert_sqlalchemy_type.register(value_equals(str))
257-
@convert_sqlalchemy_type.register(value_equals(sqa_types.String))
258-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Text))
259-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Unicode))
260-
@convert_sqlalchemy_type.register(value_equals(sqa_types.UnicodeText))
261-
@convert_sqlalchemy_type.register(value_equals(postgresql.INET))
262-
@convert_sqlalchemy_type.register(value_equals(postgresql.CIDR))
263-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.TSVectorType))
264-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.EmailType))
265-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.URLType))
266-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.IPAddressType))
256+
@convert_sqlalchemy_type.register(column_type_eq(str))
257+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.String))
258+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Text))
259+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Unicode))
260+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.UnicodeText))
261+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.INET))
262+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.CIDR))
263+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.TSVectorType))
264+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.EmailType))
265+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.URLType))
266+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.IPAddressType))
267267
def convert_column_to_string(type_arg: Any, **kwargs):
268268
return graphene.String
269269

270270

271-
@convert_sqlalchemy_type.register(value_equals(postgresql.UUID))
272-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.UUIDType))
273-
@convert_sqlalchemy_type.register(value_equals(uuid.UUID))
271+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.UUID))
272+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.UUIDType))
273+
@convert_sqlalchemy_type.register(column_type_eq(uuid.UUID))
274274
def convert_column_to_uuid(
275275
type_arg: Any,
276276
**kwargs,
277277
):
278278
return graphene.UUID
279279

280280

281-
@convert_sqlalchemy_type.register(value_equals(sqa_types.DateTime))
282-
@convert_sqlalchemy_type.register(value_equals(datetime.datetime))
281+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.DateTime))
282+
@convert_sqlalchemy_type.register(column_type_eq(datetime.datetime))
283283
def convert_column_to_datetime(
284284
type_arg: Any,
285285
**kwargs,
286286
):
287287
return graphene.DateTime
288288

289289

290-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Time))
291-
@convert_sqlalchemy_type.register(value_equals(datetime.time))
290+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Time))
291+
@convert_sqlalchemy_type.register(column_type_eq(datetime.time))
292292
def convert_column_to_time(
293293
type_arg: Any,
294294
**kwargs,
295295
):
296296
return graphene.Time
297297

298298

299-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Date))
300-
@convert_sqlalchemy_type.register(value_equals(datetime.date))
299+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Date))
300+
@convert_sqlalchemy_type.register(column_type_eq(datetime.date))
301301
def convert_column_to_date(
302302
type_arg: Any,
303303
**kwargs,
304304
):
305305
return graphene.Date
306306

307307

308-
@convert_sqlalchemy_type.register(value_equals(sqa_types.SmallInteger))
309-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Integer))
310-
@convert_sqlalchemy_type.register(value_equals(int))
308+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.SmallInteger))
309+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Integer))
310+
@convert_sqlalchemy_type.register(column_type_eq(int))
311311
def convert_column_to_int_or_id(
312312
type_arg: Any,
313313
column: Optional[Union[MapperProperty, hybrid_property]] = None,
@@ -319,28 +319,28 @@ def convert_column_to_int_or_id(
319319
) # fixme drop the primary key processing in another pr
320320

321321

322-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Boolean))
323-
@convert_sqlalchemy_type.register(value_equals(bool))
322+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Boolean))
323+
@convert_sqlalchemy_type.register(column_type_eq(bool))
324324
def convert_column_to_boolean(
325325
type_arg: Any,
326326
**kwargs,
327327
):
328328
return graphene.Boolean
329329

330330

331-
@convert_sqlalchemy_type.register(value_equals(float))
332-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Float))
333-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Numeric))
334-
@convert_sqlalchemy_type.register(value_equals(sqa_types.BigInteger))
331+
@convert_sqlalchemy_type.register(column_type_eq(float))
332+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Float))
333+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Numeric))
334+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.BigInteger))
335335
def convert_column_to_float(
336336
type_arg: Any,
337337
**kwargs,
338338
):
339339
return graphene.Float
340340

341341

342-
@convert_sqlalchemy_type.register(value_equals(postgresql.ENUM))
343-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Enum))
342+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.ENUM))
343+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Enum))
344344
def convert_enum_to_enum(
345345
type_arg: Any,
346346
column: Optional[Union[MapperProperty, hybrid_property]] = None,
@@ -354,7 +354,7 @@ def convert_enum_to_enum(
354354

355355

356356
# TODO Make ChoiceType conversion consistent with other enums
357-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.ChoiceType))
357+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.ChoiceType))
358358
def convert_choice_to_enum(
359359
type_arg: sqa_utils.ChoiceType,
360360
column: Optional[Union[MapperProperty, hybrid_property]] = None,
@@ -372,7 +372,7 @@ def convert_choice_to_enum(
372372
return graphene.Enum(name, column.type.choices)
373373

374374

375-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.ScalarListType))
375+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.ScalarListType))
376376
def convert_scalar_list_to_list(
377377
type_arg: Any,
378378
**kwargs,
@@ -388,8 +388,8 @@ def init_array_list_recursive(inner_type, n):
388388
)
389389

390390

391-
@convert_sqlalchemy_type.register(value_equals(sqa_types.ARRAY))
392-
@convert_sqlalchemy_type.register(value_equals(postgresql.ARRAY))
391+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.ARRAY))
392+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.ARRAY))
393393
def convert_array_to_list(
394394
type_arg: Any,
395395
column: Optional[Union[MapperProperty, hybrid_property]] = None,
@@ -409,26 +409,26 @@ def convert_array_to_list(
409409
)
410410

411411

412-
@convert_sqlalchemy_type.register(value_equals(postgresql.HSTORE))
413-
@convert_sqlalchemy_type.register(value_equals(postgresql.JSON))
414-
@convert_sqlalchemy_type.register(value_equals(postgresql.JSONB))
412+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.HSTORE))
413+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.JSON))
414+
@convert_sqlalchemy_type.register(column_type_eq(postgresql.JSONB))
415415
def convert_json_to_string(
416416
type_arg: Any,
417417
**kwargs,
418418
):
419419
return JSONString
420420

421421

422-
@convert_sqlalchemy_type.register(value_equals(sqa_utils.JSONType))
423-
@convert_sqlalchemy_type.register(value_equals(sqa_types.JSON))
422+
@convert_sqlalchemy_type.register(column_type_eq(sqa_utils.JSONType))
423+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.JSON))
424424
def convert_json_type_to_string(
425425
type_arg: Any,
426426
**kwargs,
427427
):
428428
return JSONString
429429

430430

431-
@convert_sqlalchemy_type.register(value_equals(sqa_types.Variant))
431+
@convert_sqlalchemy_type.register(column_type_eq(sqa_types.Variant))
432432
def convert_variant_to_impl_type(
433433
type_arg: sqa_types.Variant,
434434
column: Optional[Union[MapperProperty, hybrid_property]] = None,
@@ -446,7 +446,7 @@ def convert_variant_to_impl_type(
446446
)
447447

448448

449-
@convert_sqlalchemy_type.register(value_equals(Decimal))
449+
@convert_sqlalchemy_type.register(column_type_eq(Decimal))
450450
def convert_sqlalchemy_hybrid_property_type_decimal(type_arg: Any, **kwargs):
451451
# The reason Decimal should be serialized as a String is because this is a
452452
# base10 type used in things like money, and string allows it to not

graphene_sqlalchemy/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def register(self, matcher_function: Callable[[Any], bool], func=None):
203203
return func
204204

205205

206-
def value_equals(value: Any) -> Callable[[Any], bool]:
206+
def column_type_eq(value: Any) -> Callable[[Any], bool]:
207207
"""A simple function that makes the equality based matcher functions for
208208
SingleDispatchByMatchFunction prettier"""
209209
return lambda x: (x == value)

0 commit comments

Comments
 (0)