lib.FileContext: Beautify NotImplementedErrors

Each wrapper method throws a NotImplementedError by default. Make
that error a little more descriptive in case it really gets thrown.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-22 07:21:13 +02:00
commit 6a3cf7a283
Signed by: jan
GPG key ID: 3750640C9E25DD61

View file

@ -129,31 +129,31 @@ class FileContext(abc.ABC):
title=title, owner=owner, group=group, mode=mode_str, atomic=atomic) title=title, owner=owner, group=group, mode=mode_str, atomic=atomic)
async def _unlink(self, path: str) -> None: async def _unlink(self, path: str) -> None:
raise NotImplementedError(f'{self.log_name}: unlink() is not implemented') raise NotImplementedError(f'{self.log_name}: unlink("{path}") is not implemented')
async def unlink(self, path: str) -> None: async def unlink(self, path: str) -> None:
return await self._unlink(path) return await self._unlink(path)
async def _erase(self, path: str) -> None: async def _erase(self, path: str) -> None:
raise NotImplementedError(f'{self.log_name}: erase() is not implemented') raise NotImplementedError(f'{self.log_name}: erase("{path}") is not implemented')
async def erase(self, path: str) -> None: async def erase(self, path: str) -> None:
return await self._erase(path) return await self._erase(path)
async def _rename(self, src: str, dst: str) -> None: async def _rename(self, src: str, dst: str) -> None:
raise NotImplementedError(f'{self.log_name}: rename() is not implemented') raise NotImplementedError(f'{self.log_name}: rename("{path}") is not implemented')
async def rename(self, src: str, dst: str) -> None: async def rename(self, src: str, dst: str) -> None:
return await self._rename(src, dst) return await self._rename(src, dst)
async def _mktemp(self, tmpl: str, directory: bool) -> None: async def _mktemp(self, tmpl: str, directory: bool) -> None:
raise NotImplementedError(f'{self.log_name}: mktemp() is not implemented') raise NotImplementedError(f'{self.log_name}: mktemp("{path}") is not implemented')
async def mktemp(self, tmpl: str, directory: bool=False) -> None: async def mktemp(self, tmpl: str, directory: bool=False) -> None:
return await self._mktemp(tmpl, directory) return await self._mktemp(tmpl, directory)
async def _chown(self, path: str, owner: str|None, group: str|None) -> None: async def _chown(self, path: str, owner: str|None, group: str|None) -> None:
raise NotImplementedError(f'{self.log_name}: chown() is not implemented') raise NotImplementedError(f'{self.log_name}: chown("{path}") is not implemented')
async def chown(self, path: str, owner: str|None=None, group: str|None=None) -> None: async def chown(self, path: str, owner: str|None=None, group: str|None=None) -> None:
if owner is None and group is None: if owner is None and group is None:
@ -161,13 +161,13 @@ class FileContext(abc.ABC):
return await self._chown(path, owner, group) return await self._chown(path, owner, group)
async def _chmod(self, path: str, mode: int) -> None: async def _chmod(self, path: str, mode: int) -> None:
raise NotImplementedError(f'{self.log_name}: chmod() is not implemented') raise NotImplementedError(f'{self.log_name}: chmod("{path}") is not implemented')
async def chmod(self, path: str, mode: int) -> None: async def chmod(self, path: str, mode: int) -> None:
return await self._chmod(path, mode) return await self._chmod(path, mode)
async def _stat(self, path: str, follow_symlinks: bool) -> StatResult: async def _stat(self, path: str, follow_symlinks: bool) -> StatResult:
raise NotImplementedError(f'{self.log_name}: lstat() is not implemented') raise NotImplementedError(f'{self.log_name}: lstat("{path}") is not implemented')
async def stat(self, path: str, follow_symlinks: bool=True) -> StatResult: async def stat(self, path: str, follow_symlinks: bool=True) -> StatResult:
if not isinstance(path, str): if not isinstance(path, str):