Python future.utils 模块,with_metaclass() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用future.utils.with_metaclass()

项目:magic-constraints    作者:huntzhan    | 项目源码 | 文件源码
def generate_immutable_abc(supercls, mutable_subclass):

    class ABCImmutableMeta(ABCMeta):

        def __subclasscheck__(cls, subclass):
            if not issubclass(subclass, supercls):
                return False
            return not issubclass(subclass, mutable_subclass)

    class ABCImmutable(with_metaclass(ABCImmutableMeta, object)):
        pass

    # dirty hack to assert issubclass(ABCImmutable, supercls).
    supercls._abc_cache.add(ABCImmutable)

    return ABCImmutable
项目:magic-constraints    作者:huntzhan    | 项目源码 | 文件源码
def __new__(generator_cls, ABC):
        MetaMagicType = create_metaclass(
            BasicMetaMagicType,
            generator_cls,
        )
        MagicType = create_class(
            with_metaclass(MetaMagicType, BasicMagicType),
            generator_cls,
        )

        MagicType.generator_cls = generator_cls
        MagicType.main_cls = ABC
        MagicType.partial_cls = None

        return MagicType
项目:kiwi    作者:papaya-mobile    | 项目源码 | 文件源码
def test_inherit_2(self):
        class Hi(TableBase):
            id = HashKeyField()

        class Table(with_metaclass(TableMeta, Hi)):
            pass

        class User(Table, Hi):
            name = RangeKeyField(data_type=NUMBER)

        self._check_rangekey(User)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_with_metaclass_and_dict(self):
        """
        Issue #91 (for newdict instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, dict)):
            pass
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_with_metaclass_and_str(self):
        """
        Issue #91 (for newstr instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, str)):
            pass
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_with_metaclass_and_int(self):
        """
        Issue #91 (for newint instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, int)):
            pass
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_with_metaclass_and_list(self):
        """
        Issue #91 (for newdict instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, list)):
            pass
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_with_metaclass_and_object(self):
        """
        Issue #91
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, object)):
            pass