何时使用"raise NotImplementedError"? [英] When to use 'raise NotImplementedError'?

查看:105
本文介绍了何时使用"raise NotImplementedError"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否在提醒自己和您的团队正确实施课堂? 我没有完全使用这样的抽象类:

Is it to remind yourself and your team to implement the class correctly? I don't fully get the use of an abstract class like this:

class RectangularRoom(object):
    def __init__(self, width, height):
        raise NotImplementedError

    def cleanTileAtPosition(self, pos):
        raise NotImplementedError

    def isTileCleaned(self, m, n):
        raise NotImplementedError

推荐答案

文档说明

在用户定义的基类中,当抽象方法要求派生类重写该方法时,或者在开发该类以指示仍需要添加实际实现时,应引发此异常.

In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added.

请注意,尽管主要说明的用例是该错误是对应该在继承的类上实现的抽象方法的指示,但您可以随意使用它,例如用于指示TODO标记.

Note that although the main stated use case this error is the indication of abstract methods that should be implemented on inherited classes, you can use it anyhow you'd like, like for indication of a TODO marker.

这篇关于何时使用"raise NotImplementedError"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆