本文整理汇总了Python中abc.ABCMeta.__new__方法的典型用法代码示例。如果您正苦于以下问题:Python ABCMeta.__new__方法的具体用法?Python ABCMeta.__new__怎么用?Python ABCMeta.__new__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类abc.ABCMeta
的用法示例。
在下文中一共展示了ABCMeta.__new__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from abc import ABCMeta [as 别名]
# 或者: from abc.ABCMeta import __new__ [as 别名]
def __new__(metacls, name, bases, dct):
schema_attrs = metacls._get_schema_attributes(
name=name,
bases=bases,
dct=dct
)
dct.update(schema_attrs)
cls = ABCMeta.__new__(metacls, name, bases, dct)
# allow self-references etc.
for field_name, field in cls._fields.iteritems():
field.set_parent(cls)
if metacls.auto_register:
auto_store.add_record(cls, _bump_stack_level=True)
return cls
示例2: from_class
# 需要导入模块: from abc import ABCMeta [as 别名]
# 或者: from abc.ABCMeta import __new__ [as 别名]
def from_class(metacls, cls, auto_store=True):
"""Create proper PySchema class from cls
Any methods and attributes will be transferred to the
new object
"""
if auto_store:
def wrap(cls):
return cls
else:
wrap = no_auto_store()
return wrap(metacls.__new__(
metacls,
cls.__name__,
(Record,),
dict(cls.__dict__)
))
示例3: __new__
# 需要导入模块: from abc import ABCMeta [as 别名]
# 或者: from abc.ABCMeta import __new__ [as 别名]
def __new__(mcls, name, bases, namespace, **kwargs):
def hot_patch(required, existing):
if required not in namespace and existing in namespace:
namespace[required] = namespace[existing]
hot_patch('__iter__', 'get_data')
hot_patch('__len__', 'size')
return ABCMeta.__new__(mcls, name, bases, namespace, **kwargs)
示例4: __new__
# 需要导入模块: from abc import ABCMeta [as 别名]
# 或者: from abc.ABCMeta import __new__ [as 别名]
def __new__(mcls, name, bases, namespace):
cls = ABCMeta.__new__(mcls, name, bases, namespace)
name = utils.convert_class_name(name)
cls.models[name] = cls
return cls