#!/usr/bin/env python3 # © H2O.ai 2018; -*- encoding: utf-8 -*- # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. #------------------------------------------------------------------------------- """ Utility for checking types at runtime. """ import typesentry import warnings import sys from typesentry import U from datatable.utils.terminal import term _tc = typesentry.Config() typed = _tc.typed is_type = _tc.is_type name_type = _tc.name_type TTypeError = _tc.TypeError TValueError = _tc.ValueError class TImportError(ImportError): """Custom (soft) import error.""" _handle_ = TTypeError._handle_ TTypeError.__module__ = "datatable" TValueError.__module__ = "datatable" TImportError.__module__ = "datatable"
def check_type(instance, type_hint): """Return True if instance corresponds to its type hint.""" return typesentry.Config().is_type(instance, type_hint)