[Answered ]-Class based views and 'raise NotImplementedError'

2👍

✅

Well, you do it correctly, call raise NotImplementedError() inside the functions that are not implemented and it will get raised every time these functions get called:

>>> class NotImplementedError(Exception):
...     pass
... 
>>> class FooView(object):
...     def get(self):
...         raise NotImplementedError()
... 
>>> v = FooView()
>>> v.get()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in get
__main__.NotImplementedError

You can raise the exception anywhere you deem it useful, e.g. in the constructor to indicate that the whole class is not implemented:

>>> class FooView(object):
...     def __init__(self):
...         raise NotImplementedError()
... 
>>> v = FooView()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
__main__.NotImplementedError

Leave a comment