On Sat, Dec 26, 2015 at 4:33 PM, Ben Finney
Guido van Rossum
writes: No, raising NotImplementedError means that a subclass was supposed to implement the method. In this case it's different -- it should appear as if the method isn't implemented to code that checks for the method's presence.
Understood, thanks for explaining the difference.
Introspecting whether the code raises NotImplementedError is unfeasible. We explicitly decided that setting the method to None indicates that it should be considered as absent by code that checks for the method's presence.
Oh, you mean setting the attribute so it's not a method at all but a simple non-callable object? That makes sense.
Why recommend ‘None’, though? We now have the ‘NotImplemented’ object; why not set the attribute of the class as ‘foo = NotImplemented’?
Too late by many language releases, and not worth fixing. Either way it's an arbitrary token that you would have to check for specially and whose meaning you'd have to look up. Also, NotImplemented has very special semantics (its main use is for *binary* operators to indicate "not overloaded on this argument, try the other") -- this has nothing to do with that. (If I had to do it over again, I'd choose more different names for the exception you raise to indicate that a method should be implemented by a subclass, and the value you return to indicate that the other argument of a binary operator should be given a chance. But that's also too late by many releases.) -- --Guido van Rossum (python.org/~guido)