# HG changeset patch # User Paul Boddie # Date 1339346317 -7200 # Node ID 3815443bf7de8c20292907081de34c3bbf4ae704 # Parent 907900242a338a6480bc569dfc18e5378b441b33 Added a test of attribute usage and try...except statements. diff -r 907900242a33 -r 3815443bf7de tests/attribute_access_type_restriction_exception.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_exception.py Sun Jun 10 18:38:37 2012 +0200 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +class C: + def __init__(self): + self.visitor = self + + def default(self, node): + return 123 + + def dispatch(self, node): + try: + return node.visit(self.visitor) + except AttributeError: + return self.visitor.default(node) + +class N: + def visit(self, visitor): + return 456 + +c = C() +n = N() +result_456 = c.dispatch(n) + +# vim: tabstop=4 expandtab shiftwidth=4