2016-11-23 | Paul Boddie | file changeset files shortlog | Added print statements for testing purposes. |
paul@2 | 1 | class C: |
paul@2 | 2 | def c(self): |
paul@2 | 3 | return 1 |
paul@2 | 4 | |
paul@2 | 5 | class D: |
paul@2 | 6 | def d(self): |
paul@2 | 7 | return 3 |
paul@2 | 8 | |
paul@2 | 9 | a = 4 |
paul@2 | 10 | |
paul@2 | 11 | def f(x): |
paul@2 | 12 | x.c() |
paul@43 | 13 | def g(y, x=x): # x must be introduced as default here |
paul@2 | 14 | if y: |
paul@2 | 15 | x = D() |
paul@2 | 16 | return x.d(), y, a # UnboundLocalError in Python (if y is a false value) |
paul@2 | 17 | return g |
paul@2 | 18 | |
paul@2 | 19 | result = f(C())(2) |
paul@214 | 20 | print result[0] |
paul@214 | 21 | print result[1] |
paul@214 | 22 | print result[2] |
paul@2 | 23 | assert result == (3, 2, 4) |