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


Python abc.abstractproperty方法代码示例

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


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

示例1: _create_property

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def _create_property(property_name,
                     docstring=None,
                     readonly=False,
                     required=False):
    def getter(self):
        return self.__getattribute__('_' + property_name)

    def setter(self, value):
        self.__setattr__('_' + property_name, value)

    if readonly is True:
        setter = None
    if required is False:
        absprop = None
    else:
        absprop = abstractproperty(None)

    return property(fget=getter, fset=setter, doc=docstring), absprop 
开发者ID:Marcello-Sega,项目名称:pytim,代码行数:20,代码来源:properties.py

示例2: verify_interface

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def verify_interface(iface, klass):
    for method in iface.__abstractmethods__:
        if not hasattr(klass, method):
            raise InterfaceNotImplemented(
                "{0} is missing a {1!r} method".format(klass, method)
            )
        if isinstance(getattr(iface, method), abc.abstractproperty):
            # Can't properly verify these yet.
            continue
        sig = signature(getattr(iface, method))
        actual = signature(getattr(klass, method))
        if sig != actual:
            raise InterfaceNotImplemented(
                "{0}.{1}'s signature differs from the expected. Expected: "
                "{2!r}. Received: {3!r}".format(
                    klass, method, sig, actual
                )
            ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:utils.py

示例3: verify_interface

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def verify_interface(iface, klass):
    for method in iface.__abstractmethods__:
        if not hasattr(klass, method):
            raise InterfaceNotImplemented(
                "{0} is missing a {1!r} method".format(klass, method)
            )
        if isinstance(getattr(iface, method), abc.abstractproperty):
            # Can't properly verify these yet.
            continue
        sig = signature(getattr(iface, method))
        actual = signature(getattr(klass, method))
        if sig != actual:
            raise InterfaceNotImplemented(
                "{0}.{1}'s signature differs from the expected. Expected: "
                "{2!r}. Received: {3!r}".format(
                    klass, method, sig, actual
                )
            )


# No longer needed as of 2.2, but retained because we have external consumers
# who use it. 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:utils.py

示例4: verify_interface

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def verify_interface(iface, klass):
    for method in iface.__abstractmethods__:
        if not hasattr(klass, method):
            raise InterfaceNotImplemented(
                "{} is missing a {!r} method".format(klass, method)
            )
        if isinstance(getattr(iface, method), abc.abstractproperty):
            # Can't properly verify these yet.
            continue
        sig = signature(getattr(iface, method))
        actual = signature(getattr(klass, method))
        if sig != actual:
            raise InterfaceNotImplemented(
                "{}.{}'s signature differs from the expected. Expected: "
                "{!r}. Received: {!r}".format(
                    klass, method, sig, actual
                )
            )


# No longer needed as of 2.2, but retained because we have external consumers
# who use it. 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:utils.py

示例5: test_abstractproperty_basics

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def test_abstractproperty_basics(self):
        @abc.abstractproperty
        def foo(self): pass
        self.assertTrue(foo.__isabstractmethod__)
        def bar(self): pass
        self.assertFalse(hasattr(bar, "__isabstractmethod__"))

        class C(metaclass=abc.ABCMeta):
            @abc.abstractproperty
            def foo(self): return 3
        self.assertRaises(TypeError, C)
        class D(C):
            @property
            def foo(self): return super().foo
        self.assertEqual(D().foo, 3)
        self.assertFalse(getattr(D.foo, "__isabstractmethod__", False)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_abc.py

示例6: code_size

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def code_size(self):
    """Return the size of each code.

    This number is a constant and should agree with the output of the `encode`
    op (e.g. if rel_codes is the output of self.encode(...), then it should have
    shape [N, code_size()]).  This abstractproperty should be overridden by
    implementations.

    Returns:
      an integer constant
    """
    pass 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:14,代码来源:box_coder.py

示例7: test_property_names

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def test_property_names(self):
        # If a method is annotated with @property, its name should
        # match the attr regex. Since by default the attribute regex is the same
        # as the method regex, we override it here.
        methods = astroid.extract_node(
            """
        import abc

        def custom_prop(f):
          return property(f)

        class FooClass(object):
          @property
          def FOO(self): #@
            pass

          @property
          def bar(self): #@
            pass

          @abc.abstractproperty
          def BAZ(self): #@
            pass

          @custom_prop
          def QUX(self): #@
            pass
        """
        )
        with self.assertNoMessages():
            self.checker.visit_functiondef(methods[0])
            self.checker.visit_functiondef(methods[2])
            self.checker.visit_functiondef(methods[3])
        with self.assertAddsMessages(
            Message(
                "invalid-name",
                node=methods[1],
                args=("Attribute", "bar", "'[A-Z]+' pattern"),
            )
        ):
            self.checker.visit_functiondef(methods[1]) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:43,代码来源:unittest_checker_base.py

示例8: test_abstractproperty_basics

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def test_abstractproperty_basics(self):
        @abc.abstractproperty
        def foo(self): pass
        self.assertTrue(foo.__isabstractmethod__)
        def bar(self): pass
        self.assertFalse(hasattr(bar, "__isabstractmethod__"))

        class C:
            __metaclass__ = abc.ABCMeta
            @abc.abstractproperty
            def foo(self): return 3
        class D(C):
            @property
            def foo(self): return super(D, self).foo
        self.assertEqual(D().foo, 3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_abc.py

示例9: test_abstractmethod_integration

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractproperty [as 别名]
def test_abstractmethod_integration(self):
        for abstractthing in [abc.abstractmethod, abc.abstractproperty]:
            class C:
                __metaclass__ = abc.ABCMeta
                @abstractthing
                def foo(self): pass  # abstract
                def bar(self): pass  # concrete
            self.assertEqual(C.__abstractmethods__, set(["foo"]))
            self.assertRaises(TypeError, C)  # because foo is abstract
            self.assertTrue(isabstract(C))
            class D(C):
                def bar(self): pass  # concrete override of concrete
            self.assertEqual(D.__abstractmethods__, set(["foo"]))
            self.assertRaises(TypeError, D)  # because foo is still abstract
            self.assertTrue(isabstract(D))
            class E(D):
                def foo(self): pass
            self.assertEqual(E.__abstractmethods__, set())
            E()  # now foo is concrete, too
            self.assertFalse(isabstract(E))
            class F(E):
                @abstractthing
                def bar(self): pass  # abstract override of concrete
            self.assertEqual(F.__abstractmethods__, set(["bar"]))
            self.assertRaises(TypeError, F)  # because bar is abstract now
            self.assertTrue(isabstract(F)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_abc.py


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