First version to merge

This commit is contained in:
adator
2025-08-21 00:59:13 +02:00
parent 0a4e185fe8
commit 06fc6c4d82
8 changed files with 197 additions and 108 deletions

View File

@@ -1,6 +1,7 @@
'''
Main utils library.
'''
import gc
from pathlib import Path
from re import sub
from typing import Literal, Optional, Any
@@ -50,6 +51,25 @@ def get_datetime() -> datetime:
"""
return datetime.now()
def run_python_garbage_collector() -> int:
"""Run Python garbage collector
Returns:
int: The number of unreachable objects is returned.
"""
return gc.collect()
def get_number_gc_objects(your_object_to_count: Optional[Any] = None) -> int:
"""Get The number of objects tracked by the collector (excluding the list returned).
Returns:
int: Number of tracked objects by the collector
"""
if your_object_to_count is None:
return len(gc.get_objects())
return sum(1 for obj in gc.get_objects() if isinstance(obj, your_object_to_count))
def generate_random_string(lenght: int) -> str:
"""Retourn une chaîne aléatoire en fonction de la longueur spécifiée.