Raising NotImplementedType while only classes or instances are allowed
19 self.limits = (1, 10)
20
21 def get_number(self, min_max):
22 raise NotImplemented 23
24 def smethod():
25 """static method-to-be"""
Description
Raising objects other than a class, an instance or a string can cause a TypeError
.
There can be cases where the value being raised is dynamically set. One common example is initially setting the value to None
and assigning other objects based on a condition. Doing so can affect readability and is generally not recommended. In such cases, either re-write the block or ignore the issue for this file.
Bad practice
error = None
if not isinstance(foo, int):
error = TypeError('Expected foo to be of type int')
else:
error = ValueError('Unknown value')
raise error
Recommended
if not isinstance(foo, int):
raise TypeError('Expected foo to be of type int')
else:
raise ValueError('Unknown value')