def validate ( self, object, name, value ):

        from traits.adaptation.api import adapt

        if value is None:
            if self._allow_none:
                return value
            else:
                self.validate_failed( object, name, value )

        if isinstance( self.aClass, basestring ):
            self.resolve_class( object, name, value )

        if self.adapt < 0:
            if isinstance( value, self.aClass ):
                return value
        elif self.adapt == 0:
            try:
                return adapt( value, self.aClass )
            except:
                pass
        else:
            # fixme: The 'None' value is not really correct. It should return
            # the default value for the trait, but the handler does not have
            # any way to know this currently. Since the 'fast validate' code
            # does the correct thing, this should not normally be a problem.
            return adapt( value, self.aClass, None )

        self.validate_failed( object, name, value )
dataset/ETHPy150Open enthought/traits/traits/trait_handlers.py/TraitInstance.validate/original