@@ -52,3 +52,48 @@ def test_new_not_descriptor():
52
52
class C :
53
53
__new__ = str
54
54
assert C () == str (C )
55
+
56
+
57
+ def test_meta_meta_new ():
58
+ class NewDescriptor ():
59
+ def new_descriptor_new (self ):
60
+ return lambda * a , ** kw : ("a kind of NewDescriptor thing" , a , kw )
61
+
62
+ def __get__ (self , * args ):
63
+ return self .new_descriptor_new ()
64
+
65
+ def __set__ (self , * args ):
66
+ raise NotImplementedError
67
+
68
+ class MetaMeta (type ):
69
+ pass
70
+
71
+ class Meta (type , metaclass = MetaMeta ):
72
+ def __new__ (* args , ** kwargs ):
73
+ cls = super ().__new__ (* args , ** kwargs )
74
+ cls .metatype = Meta
75
+ return cls
76
+
77
+ # setup done, now testing
78
+
79
+ class aMeta (metaclass = Meta ):
80
+ pass
81
+
82
+ MetaMeta .__new__ = Meta .__new__
83
+
84
+ class stillAMeta (metaclass = Meta ):
85
+ pass
86
+
87
+ class aMetaThatIsNotAMetaMeta (metaclass = MetaMeta ):
88
+ pass
89
+
90
+ MetaMeta .__new__ = NewDescriptor ()
91
+
92
+ class notAMeta (metaclass = Meta ):
93
+ pass
94
+
95
+ assert aMeta [0 ] == 'a kind of Meta'
96
+ assert stillAMeta [0 ] == 'a kind of Meta'
97
+ assert aMetaThatIsNotAMetaMeta [0 ] == 'a kind of Meta'
98
+ assert notAMeta [0 ] == 'a kind of NewDescriptor thing'
99
+ q
0 commit comments