def __call__(self, arg_type):
        """Decorator that creates a visitor method."""

        # Delegating visitor implementation

        def _visitor_impl(new_self, arg, *args, **kwargs):
            """Actual visitor method implementation."""
            method = self[type(arg)]
            return method(new_self, arg, *args, **kwargs)

        def decorator(fn):
            self[arg_type] = fn
            # Replace all decorated methods with _visitor_impl
            return _visitor_impl

        return decorator
def __call__ ( self , arg_type ) : def _visitor_impl ( new_self , arg , * args , ** kwargs ) : method = self [ type ( arg ) ] return method ( new_self , arg , * args , ** kwargs ) def decorator ( fn ) : self [ arg_type ] = fn return _visitor_impl return decorator
Decorator that creates a visitor method.