Python Glossary Русский

Python 3.13+pathlibexception

pathlib.UnsupportedOperation

exceptions

A subclass of NotImplementedError raised when a pathlib operation is unsupported on the current platform — e.g. symlink_to()/readlink() without os.symlink, or PosixPath on Windows. Python 3.13+.

Syntax

pathlib.UnsupportedOperation

The class only exists since Python 3.13, so except pathlib.UnsupportedOperation blows up with AttributeError on 3.12 and older before anything else can go wrong. Version-portable code catches NotImplementedError instead: UnsupportedOperation is a subclass of it, and older pathlib raised NotImplementedError in these very spots. Seeing it means the operation is absent on this platform, not that your code is buggy, so handle it with a fallback branch rather than a retry.

Examples

import pathlib
Unsupported = getattr(pathlib, 'UnsupportedOperation', NotImplementedError)
print(issubclass(Unsupported, NotImplementedError))   # → True
print(issubclass(Unsupported, RuntimeError))   # → True
print(isinstance(Unsupported('symlink недоступен'), NotImplementedError))   # → True
print(hasattr(pathlib.Path, 'symlink_to'))   # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy