当前位置: 首页>>代码示例>>Python>>正文


Python abc.ABCMeta方法代码示例

本文整理汇总了Python中collections.abc.ABCMeta方法的典型用法代码示例。如果您正苦于以下问题:Python abc.ABCMeta方法的具体用法?Python abc.ABCMeta怎么用?Python abc.ABCMeta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections.abc的用法示例。


在下文中一共展示了abc.ABCMeta方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: isabstract

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ABCMeta [as 别名]
def isabstract(object):
    """Return true if the object is an abstract base class (ABC)."""
    if not isinstance(object, type):
        return False
    if object.__flags__ & TPFLAGS_IS_ABSTRACT:
        return True
    if not issubclass(type(object), abc.ABCMeta):
        return False
    if hasattr(object, '__abstractmethods__'):
        # It looks like ABCMeta.__new__ has finished running;
        # TPFLAGS_IS_ABSTRACT should have been accurate.
        return False
    # It looks like ABCMeta.__new__ has not finished running yet; we're
    # probably in __init_subclass__. We'll look for abstractmethods manually.
    for name, value in object.__dict__.items():
        if getattr(value, "__isabstractmethod__", False):
            return True
    for base in object.__bases__:
        for name in getattr(base, "__abstractmethods__", ()):
            value = getattr(object, name, None)
            if getattr(value, "__isabstractmethod__", False):
                return True
    return False 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:25,代码来源:inspect.py

示例2: abstract_class

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ABCMeta [as 别名]
def abstract_class(cls_):
    """Decorate a class, overriding __new__.

    Preventing a class from being instantiated similar to abc.ABCMeta
      but does not require an abstract method.
    """

    def __new__(cls, *args, **kwargs):
        if cls is cls_:
            raise TypeError('{} is an abstract class and may not be instantiated.'
                            .format(cls.__name__))
        return object.__new__(cls)
    cls_.__new__ = __new__
    return cls_ 
开发者ID:pyvista,项目名称:pyvista,代码行数:16,代码来源:helpers.py

示例3: test_abstract

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import ABCMeta [as 别名]
def test_abstract(self):
        class Abstract(abc.ABCMeta):

            @abc.abstractmethod
            def add(self, x, y):
                pass

            add5 = functools.partialmethod(add, 5)

        self.assertTrue(Abstract.add.__isabstractmethod__)
        self.assertTrue(Abstract.add5.__isabstractmethod__)

        for func in [self.A.static, self.A.cls, self.A.over_partial, self.A.nested, self.A.both]:
            self.assertFalse(getattr(func, '__isabstractmethod__', False)) 
开发者ID:bkerler,项目名称:android_universal,代码行数:16,代码来源:test_functools.py


注:本文中的collections.abc.ABCMeta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。