class LowerAttrMetaClass_4(type):
def __new__(cls, name, bases, dct):
attrs = ((name, value) for name, value in dct.items() if not name.startswith('__'))
lowercase_attr = dict((name.lower(), value) for name, value in attrs)
return super(LowerAttrMetaClass_4, cls).__new__(cls, name, bases, lowercase_attr)
class MetaClassTest(object, metaclass=LowerAttrMetaClass_4):
Say = "hello world"
def __init__(self, name, age):
super(MetaClassTest, self).__init__()
self.name = name
self.age = age
def Run(self):
print("MetaClassTest run method")
tmp_obj = MetaClassTest(name="zzz", age=20)
执行如上代码,总是报如下错误:
DeprecationWarning: class not set defining 'MetaClassTest' as . Was classcell propagated to type.new?
class MetaClassTest(object, metaclass=LowerAttrMetaClass_4):
Traceback (most recent call last):
File "E:/zzz/meta.py", line 286, in
tmp_obj = MetaClassTest(name="zzz", age=20)
TypeError: MetaClassTest() takes no arguments
请教:
(1)为什么会报 DeprecationWarning?
(2)为什么会报 MetaClassTest() takes no arguments,我明明传了参数进去的呀?