Skip to content

Commit 7347755

Browse files
committed
tests/basics: Add test for super() when self is closed over.
1 parent 40c1272 commit 7347755

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# test that no-arg super() works when self is closed over
2+
3+
class A:
4+
def __init__(self):
5+
self.val = 4
6+
def foo(self):
7+
# we access a member of self to check that self is correct
8+
return list(range(self.val))
9+
class B(A):
10+
def foo(self):
11+
# self is closed over because it's referenced in the list comprehension
12+
# and then super() must detect this and load from the closure cell
13+
return [self.bar(i) for i in super().foo()]
14+
def bar(self, x):
15+
return 2 * x
16+
17+
print(A().foo())
18+
print(B().foo())

0 commit comments

Comments
 (0)