Coverage for src/ezplog/types/aliases.py: 100.00%
12 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-10-16 19:04 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-10-16 19:04 +0000
1# ///////////////////////////////////////////////////////////////
2# EZPL - Type aliases for loguru sink options
3# Project: ezplog
4# ///////////////////////////////////////////////////////////////
6"""
7Type aliases mirroring the value types loguru accepts for file sinks.
9The previous `str | None` annotations were narrower than reality: values such
10as `timedelta(hours=6)` for rotation or `10` for retention already worked at
11runtime but failed type checking.
12"""
14from __future__ import annotations
16# ///////////////////////////////////////////////////////////////
17# IMPORTS
18# ///////////////////////////////////////////////////////////////
19# Standard library imports
20from collections.abc import Callable
21from datetime import time, timedelta
23# ///////////////////////////////////////////////////////////////
24# TYPE ALIASES
25# ///////////////////////////////////////////////////////////////
27RotationSpec = str | int | time | timedelta | Callable[..., bool] | None
28"""Rotation trigger: size string, byte count, time of day, interval, or predicate."""
30RetentionSpec = str | int | timedelta | Callable[..., None] | None
31"""Retention policy: duration string, file count, timedelta, or cleanup callable."""
33CompressionSpec = str | Callable[[str], None] | None
34"""Compression format name, or a callable applied to the rotated file path."""
36# ///////////////////////////////////////////////////////////////
37# CONSTANTS
38# ///////////////////////////////////////////////////////////////
40SUPPORTED_COMPRESSIONS: frozenset[str] = frozenset(
41 {"gz", "bz2", "xz", "lzma", "tar", "tar.gz", "tar.bz2", "tar.xz", "zip"}
42)
43"""Compression format names accepted by loguru."""
45# ///////////////////////////////////////////////////////////////
46# PUBLIC API
47# ///////////////////////////////////////////////////////////////
49__all__ = [
50 "RotationSpec",
51 "RetentionSpec",
52 "CompressionSpec",
53 "SUPPORTED_COMPRESSIONS",
54]