Skip to content

Commit d235e28

Browse files
author
Sylvain MARIE
committed
New method is_vtype and exposing again VType at package level
1 parent 9753f2d commit d235e28

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

vtypes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#
33
# Copyright (c) Schneider Electric Industries, 2020. All right reserved.
44

5-
from vtypes.core import vtype
5+
from vtypes.core import vtype, is_vtype, VType
66

77
__all__ = [
88
'core',
9-
'vtype'
9+
'vtype', 'is_vtype', 'VType'
1010
]

vtypes/core.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,20 @@ def _get_callerframe(offset=0):
473473
for _ in range(2 + offset):
474474
frame = frame.f_back
475475
return frame
476+
477+
478+
def is_vtype(t # type: Any
479+
):
480+
# type: (...) -> bool
481+
"""
482+
Returns `True` if `t` is a `VType`, `False` otherwise.
483+
It is equivalent to `isinstance(t, VTypeMeta)` or `issubclass(t, VType)`, with exception catching.
484+
485+
:param t:
486+
:return:
487+
"""
488+
# noinspection PyBroadException
489+
try:
490+
return isinstance(t, VTypeMeta)
491+
except Exception:
492+
return False

0 commit comments

Comments
 (0)