[New-bugs-announce] [issue46733] pathlib.Path methods can raise NotImplementedError

Barney Gale report at bugs.python.org
Sat Feb 12 14:35:13 EST 2022

New submission from Barney Gale <barney.gale at gmail.com>:

The docs for NotImplementedError say:

> 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.

pathlib's use of NotImplementedError appears to be more broad. It can be raised in the following circumstances:

1. When attempting to construct a WindowsPath from a non-Windows system, and vice-versa. This is the only case where NotImplementedError is mentioned in the pathlib docs (in a repl example)
2. In glob() and rglob() when an absolute path is supplied as a pattern
3. In owner() if the pwd module isn't available
4. In group() if the grp module isn't available
5. In readlink() if os.readlink() isn't available
6. In symlink_to() if os.symlink() isn't available
7. In hardlink_to() if os.hardlink() isn't available
8. In WindowsPath.is_mount(), unconditionally

I suspect there are better choices for exception types in all these cases.

components: Library (Lib)
messages: 413142
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib.Path methods can raise NotImplementedError
type: behavior
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list