-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a number of class desugaring tests
- Loading branch information
Showing
7 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class A: | ||
def methodA(self): return "A" | ||
|
||
class B: | ||
def methodB(self): return "B" | ||
|
||
class C(A, B): | ||
def methods(self): | ||
return (self.methodA(), self.methodB()) | ||
|
||
c = C() | ||
print(c.methods()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class A: | ||
a = 10 | ||
print(A.a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def decorator(func): | ||
return lambda: "decorated!" | ||
|
||
@decorator | ||
class A: | ||
foo = 10 | ||
|
||
print(A()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def fix(d): return list(sorted(d.items())) | ||
|
||
def test_meta(name, bases, dict, **kwargs): | ||
return name, bases, fix(kwargs) | ||
|
||
|
||
nargs = (5, 4, 3, 2, 1) | ||
dargs = {"a": 10, "b": 20, "c": 30} | ||
class Bang: | ||
class Foo(10, 11, *nargs, metaclass=test_meta, other_arg="hello", **dargs): | ||
pass | ||
|
||
print(Bang.Foo) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Foo: | ||
a = 10 | ||
def test(self): | ||
a = 54 | ||
return a | ||
def metaclass(self): | ||
return "metaclass!" | ||
def __dict__(self): | ||
return "__dict__!" | ||
|
||
print(Foo.a) | ||
f = Foo() | ||
print(f.test()) | ||
print(f.test()) | ||
print(f.metaclass()) | ||
print(f.__dict__()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class A: | ||
a = "first" | ||
class B: | ||
b = "second" | ||
class C: | ||
c = "third" | ||
print(A.a) | ||
print(A.B.b) | ||
print(A.B.C.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class A: | ||
def decorator(fun): | ||
return lambda: "decorated!" | ||
|
||
@decorator | ||
class B: | ||
class C: | ||
c = 10 | ||
|
||
something = "something" | ||
|
||
print(A.something) | ||
print(A.B()) |