Mark Dickinson <dicki...@gmail.com> added the comment:

Here's the documentation, which I think explains all this clearly: briefly, 
`return NotImplemented` and `raise NotImplementedError` are the normal usages. 
`raise NotImplemented` doesn't make sense, and shouldn't be used: it'll end up 
raising a `TypeError`, sine `NotImplemented` is neither a subclass nor an 
instance of BaseException.

NotImplemented: 
https://docs.python.org/3.7/library/constants.html#NotImplemented

NotImplementedError:
https://docs.python.org/3.7/library/exceptions.html#NotImplementedError

Almost all of the grep results you're seeing do follow the expected patterns 
(either `return NotImplemented` or `raise NotImplementedError`, but a quick 
grep does show some questionable uses of `raise NotImplemented` in the standard 
library:

    MacBook-Pro:cpython mdickinson$ grep -r . -e raise   --include=\*.py  | 
grep "\bNotImplemented\b"
    ./Lib/asyncio/transports.py:    The implementation here raises 
NotImplemented for every method
    ./Lib/idlelib/debugger_r.py:        raise NotImplemented("dict_keys not 
public or pickleable")
    ./Lib/ssl.py:        raise NotImplemented("Can't dup() %s instances" %

The other way around also turns up an odd-looking `return NotImplementedError` 
(along with a false positive):

    MacBook-Pro:cpython mdickinson$ grep -r . -e return   --include=\*.py  | 
grep "\bNotImplementedError\b"
    ./Lib/ctypes/test/test_simplesubclasses.py:            return 
NotImplementedError
    ./Lib/test/test_asyncio/test_transports.py:        
self.assertRaises(NotImplementedError, transport.get_returncode)

----------
nosy: +mark.dickinson

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32464>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to