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


Python abc.abstractmethod方法代码示例

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


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

示例1: test_ignores_return_in_abstract_method_sphinx

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_ignores_return_in_abstract_method_sphinx(self):
        """Example of an abstract method documenting the return type that an
        implementation should return.
        """
        node = astroid.extract_node("""
        import abc
        class Foo(object):
            @abc.abstractmethod
            def foo(self): #@
                '''docstring ...

                :returns: Ten
                :rtype: int
                '''
                return 10
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:20,代码来源:test_check_docs.py

示例2: test_ignores_return_in_abstract_method_google

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_ignores_return_in_abstract_method_google(self):
        """Example of an abstract method documenting the return type that an
        implementation should return.
        """
        node = astroid.extract_node("""
        import abc
        class Foo(object):
            @abc.abstractmethod
            def foo(self): #@
                '''docstring ...

                Returns:
                    int: Ten
                '''
                return 10
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:20,代码来源:test_check_docs.py

示例3: test_ignores_return_in_abstract_method_numpy

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_ignores_return_in_abstract_method_numpy(self):
        """Example of an abstract method documenting the return type that an
        implementation should return.
        """
        node = astroid.extract_node("""
        import abc
        class Foo(object):
            @abc.abstractmethod
            def foo(self): #@
                '''docstring ...

                Returns
                -------
                int
                    Ten
                '''
                return 10
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:22,代码来源:test_check_docs.py

示例4: test_cache_leak

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_cache_leak(self):
        # See issue #2521.
        class A(object):
            __metaclass__ = abc.ABCMeta
            @abc.abstractmethod
            def f(self):
                pass
        class C(A):
            def f(self):
                A.f(self)
        r = weakref.ref(C)
        # Trigger cache.
        C().f()
        del C
        test_support.gc_collect()
        self.assertEqual(r(), None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_abc.py

示例5: test_abstractproperty_basics

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

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

示例6: test_abstractclassmethod_basics

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_abstractclassmethod_basics(self):
        @classmethod
        @abc.abstractmethod
        def foo(cls): pass
        self.assertTrue(foo.__isabstractmethod__)
        @classmethod
        def bar(cls): pass
        self.assertFalse(getattr(bar, "__isabstractmethod__", False))

        class C(metaclass=abc.ABCMeta):
            @classmethod
            @abc.abstractmethod
            def foo(cls): return cls.__name__
        self.assertRaises(TypeError, C)
        class D(C):
            @classmethod
            def foo(cls): return super().foo()
        self.assertEqual(D.foo(), 'D')
        self.assertEqual(D().foo(), 'D') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_abc.py

示例7: convert

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def convert(self, operator: OperatorBase) -> OperatorBase:
        r"""
        Convert a ``SummedOp`` into a ``ComposedOp`` or ``CircuitOp`` representing an
        approximation of e^-i*``op_sum``.

        Args:
            operator: The ``SummedOp`` to evolve.

        Returns:
            The Operator approximating op_sum's evolution.

        Raises:
            TypeError: A non-SummedOps Operator is passed into ``convert``.

        """
        raise NotImplementedError

    # TODO @abstractmethod - trotter_error_bound 
开发者ID:Qiskit,项目名称:qiskit-aqua,代码行数:20,代码来源:trotterization_base.py

示例8: __init__

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def __init__(self, protocol, chunk_size=None):
        self.chunk_size = chunk_size or CHUNK_SIZE  # The number of items to send in a single request
        if not isinstance(self.chunk_size, int):
            raise ValueError("'chunk_size' %r must be an integer" % chunk_size)
        if self.chunk_size < 1:
            raise ValueError("'chunk_size' must be a positive number")
        self.protocol = protocol

    # The following two methods are the minimum required to be implemented by subclasses, but the name and number of
    # kwargs differs between services. Therefore, we cannot make these methods abstract.

    # @abc.abstractmethod
    # def call(self, **kwargs):
    #     raise NotImplementedError()

    # @abc.abstractmethod
    # def get_payload(self, **kwargs):
    #     raise NotImplementedError() 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:20,代码来源:common.py

示例9: test_postcondition_in_abstract_class_method

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_postcondition_in_abstract_class_method(self) -> None:
        class Abstract(icontract.DBC):
            @classmethod
            @abc.abstractmethod
            @icontract.ensure(lambda result: result != 0)
            def some_func(cls: Type['Abstract'], x: int) -> int:
                pass

        class SomeClass(Abstract):
            @classmethod
            def some_func(cls: Type['SomeClass'], x: int) -> int:
                return x

        result = SomeClass.some_func(x=1)
        self.assertEqual(1, result)

        violation_error = None  # type: Optional[icontract.ViolationError]
        try:
            _ = SomeClass.some_func(x=0)
        except icontract.ViolationError as err:
            violation_error = err

        self.assertIsNotNone(violation_error)
        self.assertEqual('result != 0: result was 0', tests.error.wo_mandatory_location(str(violation_error))) 
开发者ID:Parquery,项目名称:icontract,代码行数:26,代码来源:test_postcondition.py

示例10: test_abstract_method

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_abstract_method(self) -> None:
        class A(icontract.DBC):
            @icontract.ensure(lambda result: result < 100)
            @abc.abstractmethod
            def func(self) -> int:
                pass

        class B(A):
            def func(self) -> int:
                return 1000

        b = B()
        violation_error = None  # type: Optional[icontract.ViolationError]
        try:
            b.func()
        except icontract.ViolationError as err:
            violation_error = err

        self.assertIsNotNone(violation_error)
        self.assertEqual("result < 100: result was 1000", tests.error.wo_mandatory_location(str(violation_error))) 
开发者ID:Parquery,项目名称:icontract,代码行数:22,代码来源:test_inheritance_postcondition.py

示例11: test_abstract_method_not_implemented

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_abstract_method_not_implemented(self) -> None:
        # pylint: disable=abstract-method
        class A(icontract.DBC):
            @icontract.ensure(lambda result: result < 100)
            @abc.abstractmethod
            def func(self) -> int:
                pass

        class B(A):
            pass

        type_err = None  # type: Optional[TypeError]
        try:
            _ = B()  # type: ignore
        except TypeError as err:
            type_err = err

        self.assertIsNotNone(type_err)
        self.assertEqual("Can't instantiate abstract class B with abstract methods func", str(type_err)) 
开发者ID:Parquery,项目名称:icontract,代码行数:21,代码来源:test_inheritance_postcondition.py

示例12: test_abstract_method

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def test_abstract_method(self) -> None:
        class A(icontract.DBC):
            @icontract.require(lambda x: x > 0)
            @abc.abstractmethod
            def func(self, x: int) -> int:
                pass

        class B(A):
            def func(self, x: int) -> int:
                return 1000

        b = B()
        violation_error = None  # type: Optional[icontract.ViolationError]
        try:
            b.func(x=-1)
        except icontract.ViolationError as err:
            violation_error = err

        self.assertIsNotNone(violation_error)
        self.assertEqual("x > 0: x was -1", tests.error.wo_mandatory_location(str(violation_error))) 
开发者ID:Parquery,项目名称:icontract,代码行数:22,代码来源:test_inheritance_precondition.py

示例13: setUpClass

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def setUpClass(cls):
        FinalABCMeta = final_meta_factory(ABCMeta)

        class ABCWithFinal(with_metaclass(FinalABCMeta, object)):
            a = final('ABCWithFinal: a')
            b = 'ABCWithFinal: b'

            @final
            def f(self):
                return 'ABCWithFinal: f'

            def g(self):
                return 'ABCWithFinal: g'

            @abstractmethod
            def h(self):
                raise NotImplementedError('h')

        cls.class_ = ABCWithFinal 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:21,代码来源:test_final.py

示例14: setUpClass

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def setUpClass(cls):
        FinalABCMeta = compose_types(FinalMeta, ABCMeta)

        class ABCWithFinal(with_metaclass(FinalABCMeta, object)):
            a = final('ABCWithFinal: a')
            b = 'ABCWithFinal: b'

            @final
            def f(self):
                return 'ABCWithFinal: f'

            def g(self):
                return 'ABCWithFinal: g'

            @abstractmethod
            def h(self):
                raise NotImplementedError('h')

        cls.class_ = ABCWithFinal 
开发者ID:enigmampc,项目名称:catalyst,代码行数:21,代码来源:test_final.py

示例15: __store_annotations__

# 需要导入模块: import abc [as 别名]
# 或者: from abc import abstractmethod [as 别名]
def __store_annotations__(self,zooniverse_id,max_users=float("inf"),expert_markings=False):
        """
        override the parent method so that we can apply ROIs
        read through and return all of the relevant annotations associated with the given zooniverse_id
        :param zooniverse_id: id of the subject
        :param max_users: maximum number of classifications to read in
        :param expert_markings: do we want to read in markings from experts - either yes or no, shouldn't mix
        :return:
        """
        if not(zooniverse_id in self.roi_dict):
            self.roi_dict[zooniverse_id] = self.__get_roi__(zooniverse_id)

        self.current_roi = self.roi_dict[zooniverse_id]
        OuroborosAPI.__store_annotations__(self,zooniverse_id,max_users,expert_markings)

        self.current_roi = None

    # @abc.abstractmethod
    # def __classification_to_markings__(self,classification,roi):
    #     """
    #     This is the main function projects will have to override - given a set of annotations, we need to return the list
    #     of all markings in that annotation
    #     """
    #     return [] 
开发者ID:zooniverse,项目名称:aggregation,代码行数:26,代码来源:ouroboros_api.py


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