Skip to content

Commit 3117f39

Browse files
authored
Use safer is_subclass checks (#475)
1 parent 2e91f22 commit 3117f39

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/cattrs/_compat.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def is_hetero_tuple(type: Any) -> bool:
172172

173173

174174
def is_protocol(type: Any) -> bool:
175-
return issubclass(type, Protocol) and getattr(type, "_is_protocol", False)
175+
return is_subclass(type, Protocol) and getattr(type, "_is_protocol", False)
176176

177177

178178
def is_bare_final(type) -> bool:
@@ -245,7 +245,7 @@ def is_annotated(type) -> bool:
245245
def is_tuple(type):
246246
return (
247247
type in (Tuple, tuple)
248-
or (type.__class__ is _GenericAlias and issubclass(type.__origin__, Tuple))
248+
or (type.__class__ is _GenericAlias and is_subclass(type.__origin__, Tuple))
249249
or (getattr(type, "__origin__", None) is tuple)
250250
)
251251

@@ -324,7 +324,7 @@ def is_sequence(type: Any) -> bool:
324324
type.__class__ is _GenericAlias
325325
and (
326326
(origin is not tuple)
327-
and issubclass(origin, TypingSequence)
327+
and is_subclass(origin, TypingSequence)
328328
or origin is tuple
329329
and type.__args__[1] is ...
330330
)
@@ -336,7 +336,7 @@ def is_sequence(type: Any) -> bool:
336336
def is_deque(type):
337337
return (
338338
type in (deque, Deque)
339-
or (type.__class__ is _GenericAlias and issubclass(type.__origin__, deque))
339+
or (type.__class__ is _GenericAlias and is_subclass(type.__origin__, deque))
340340
or (getattr(type, "__origin__", None) is deque)
341341
)
342342

@@ -345,7 +345,7 @@ def is_mutable_set(type):
345345
type in (TypingSet, TypingMutableSet, set)
346346
or (
347347
type.__class__ is _GenericAlias
348-
and issubclass(type.__origin__, TypingMutableSet)
348+
and is_subclass(type.__origin__, TypingMutableSet)
349349
)
350350
or (getattr(type, "__origin__", None) in (set, AbcMutableSet, AbcSet))
351351
)
@@ -355,7 +355,7 @@ def is_frozenset(type):
355355
type in (FrozenSet, frozenset)
356356
or (
357357
type.__class__ is _GenericAlias
358-
and issubclass(type.__origin__, FrozenSet)
358+
and is_subclass(type.__origin__, FrozenSet)
359359
)
360360
or (getattr(type, "__origin__", None) is frozenset)
361361
)
@@ -370,13 +370,13 @@ def is_mapping(type):
370370
type in (dict, Dict, TypingMapping, TypingMutableMapping, AbcMutableMapping)
371371
or (
372372
type.__class__ is _GenericAlias
373-
and issubclass(type.__origin__, TypingMapping)
373+
and is_subclass(type.__origin__, TypingMapping)
374374
)
375375
or (
376376
getattr(type, "__origin__", None)
377377
in (dict, AbcMutableMapping, AbcMapping)
378378
)
379-
or issubclass(type, dict)
379+
or is_subclass(type, dict)
380380
)
381381

382382
def is_counter(type):
@@ -427,7 +427,7 @@ def is_annotated(type) -> bool:
427427

428428
def is_tuple(type):
429429
return type in (Tuple, tuple) or (
430-
type.__class__ is _GenericAlias and issubclass(type.__origin__, Tuple)
430+
type.__class__ is _GenericAlias and is_subclass(type.__origin__, Tuple)
431431
)
432432

433433
def is_union_type(obj):
@@ -450,32 +450,32 @@ def is_sequence(type: Any) -> bool:
450450
type.__class__ is _GenericAlias
451451
and (
452452
type.__origin__ not in (Union, Tuple, tuple)
453-
and issubclass(type.__origin__, TypingSequence)
453+
and is_subclass(type.__origin__, TypingSequence)
454454
)
455455
or (type.__origin__ in (Tuple, tuple) and type.__args__[1] is ...)
456456
)
457457

458458
def is_deque(type: Any) -> bool:
459459
return (
460460
type in (deque, Deque)
461-
or (type.__class__ is _GenericAlias and issubclass(type.__origin__, deque))
461+
or (type.__class__ is _GenericAlias and is_subclass(type.__origin__, deque))
462462
or type.__origin__ is deque
463463
)
464464

465465
def is_mutable_set(type):
466466
return type is set or (
467-
type.__class__ is _GenericAlias and issubclass(type.__origin__, MutableSet)
467+
type.__class__ is _GenericAlias and is_subclass(type.__origin__, MutableSet)
468468
)
469469

470470
def is_frozenset(type):
471471
return type is frozenset or (
472-
type.__class__ is _GenericAlias and issubclass(type.__origin__, FrozenSet)
472+
type.__class__ is _GenericAlias and is_subclass(type.__origin__, FrozenSet)
473473
)
474474

475475
def is_mapping(type):
476476
return type in (TypingMapping, dict) or (
477477
type.__class__ is _GenericAlias
478-
and issubclass(type.__origin__, TypingMapping)
478+
and is_subclass(type.__origin__, TypingMapping)
479479
)
480480

481481
bare_generic_args = {

0 commit comments

Comments
 (0)