def __init__(self, type_error=TsTypeError, value_error=TsValueError,
                 disabled=False, soft_exceptions=True):
        """
        Create new type-checking configuration.

        :param type_error: exception class that should be used when a type
            error occurs. It is recommended that this class derives from the
            standard ``TypeError``.
        :param value_error: exception class that should be used when a value
            error occurs. It is recommended that this class derives from the
            standard ``ValueError``.
        :param disabled: if True, then all type-checking will be disabled.
        :param soft_exceptions: if True, then a custom exceptions handler will
            be installed at the console level, which will catch any exception
            with method ``._handle_()`` and use that method to report the
            error.
        """
        self.TypeError = type_error
        self.ValueError = value_error
        self.typed = self._make_typed(disabled)
        self.supply_src = False
        if soft_exceptions:
            global system_except_hook
            assert callable(getattr(type_error, "_handle_")), \
                "Class %s missing method ._handle_()" % type_error.__name__
            assert callable(getattr(value_error, "_handle_")), \
                "Class %s missing method ._handle_()" % value_error.__name__
            try:
                s = Signature(func=traceback.print_tb, types=tuple(),
                              typesentry_config=self)
                type_error("test type_error", src=s)
                self.supply_src = True
            except TypeError as e:
                print(e)
                raise RuntimeError("Class %s must take parameter `src` when "
                                   "soft exceptions are used"
                                   % type_error.__name__)
            # Make sure that we only ever attempt to set the excepthook once
            if not system_except_hook:
                system_except_hook = sys.excepthook
                sys.excepthook = typesentry_except_hook
def __init__ ( self , type_error = TsTypeError , value_error = TsValueError , disabled = False , soft_exceptions = True ) : self . TypeError = type_error self . ValueError = value_error self . typed = self . _make_typed ( disabled ) self . supply_src = False if soft_exceptions : global system_except_hook assert callable ( getattr ( type_error , "_handle_" ) ) , "Class %s missing method ._handle_()" % type_error . __name__ assert callable ( getattr ( value_error , "_handle_" ) ) , "Class %s missing method ._handle_()" % value_error . __name__ try : s = Signature ( func = traceback . print_tb , types = tuple ( ) , typesentry_config = self ) type_error ( "test type_error" , src = s ) self . supply_src = True except TypeError as e : print ( e ) raise RuntimeError ( "Class %s must take parameter `src` when " "soft exceptions are used" % type_error . __name__ ) if not system_except_hook : system_except_hook = sys . excepthook sys . excepthook = typesentry_except_hook
Create new type-checking configuration.

        :param type_error: exception class that should be used when a type
            error occurs. It is recommended that this class derives from the
            standard ``TypeError``.
        :param value_error: exception class that should be used when a value
            error occurs. It is recommended that this class derives from the
            standard ``ValueError``.
        :param disabled: if True, then all type-checking will be disabled.
        :param soft_exceptions: if True, then a custom exceptions handler will
            be installed at the console level, which will catch any exception
            with method ``._handle_()`` and use that method to report the
            error.