Skip to content

Commit 0e08819

Browse files
author
Sylvain MARIE
committed
Minor optimization: since we have a __type__ field, let's use it instead of using a filtered version of __bases__
1 parent eee50fe commit 0e08819

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

vtypes/core.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def __instancecheck__(cls, # type: VTypeMeta
219219
:param obj:
220220
:return:
221221
"""
222-
# first make sure that `obj` is an instance of all bases (this includes value validation in case of VTypes)
223-
if not all(isinstance(obj, t) for t in cls.__bases__ if t is not VType):
222+
# first make sure that `obj` is an instance of all the base types
223+
if not all(isinstance(obj, t) for t in cls.__type__):
224224
return False
225225

226226
# then validate the value with validators on this class
@@ -283,12 +283,12 @@ def has_valid_type(cls, obj):
283283
:param obj:
284284
:return:
285285
"""
286-
# should be an instance of all base types (except VType)
286+
# should be an instance of all base types
287287
# for VTypes, we rely on has_valid_type instead of isinstance to avoid value check
288-
for t in cls.__bases__:
289-
if t is VType:
290-
continue
291-
elif isinstance(t, VTypeMeta):
288+
for t in cls.__type__:
289+
# if t is VType:
290+
# continue
291+
if isinstance(t, VTypeMeta):
292292
if not t.has_valid_type(obj):
293293
return False
294294
elif not isinstance(obj, t):
@@ -319,10 +319,10 @@ def has_valid_value(cls,
319319
return False
320320

321321
if inherited_validators:
322-
for t in cls.__bases__:
323-
if t is VType:
324-
continue
325-
elif isinstance(t, VTypeMeta) and not t.has_valid_value(obj, inherited_validators=True):
322+
for t in cls.__type__:
323+
# if t is VType:
324+
# continue
325+
if isinstance(t, VTypeMeta) and not t.has_valid_value(obj, inherited_validators=True):
326326
return False
327327
else:
328328
continue

0 commit comments

Comments
 (0)