hbutils.system.filesystem.tempfile
Temporary directory utilities with Windows-compatible cleanup behavior.
This module provides a backport-compatible TemporaryDirectory implementation
for environments where the standard library’s behavior can raise
PermissionError during cleanup (notably Windows on Python 3.7). For Python
3.10 and newer, the standard library implementation is re-exported directly.
The module exposes the following public component:
TemporaryDirectory- Context manager for creating and cleaning up temporary directories with Windows-friendly error handling.
Note
On Python 3.10+, this module transparently re-exports
tempfile.TemporaryDirectory.
Example:
>>> from hbutils.system.filesystem.tempfile import TemporaryDirectory
>>> with TemporaryDirectory(prefix='demo_') as tmpdir:
... # Use tmpdir for temporary operations
... pass
>>> # Directory is automatically cleaned up after exiting the context
GenericAlias
- hbutils.system.filesystem.tempfile.GenericAlias = <class 'types.GenericAlias'>
Represent a PEP 585 generic type
E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
__all__
- hbutils.system.filesystem.tempfile.__all__ = ['TemporaryDirectory']
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
TemporaryDirectory
- class hbutils.system.filesystem.tempfile.TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False)[source]
Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager. For example:
- with TemporaryDirectory() as tmpdir:
…
Upon exiting the context, the directory and everything contained in it are removed.