Avoid eager imports to fix circular dependency

This commit is contained in:
thePR0M3TH3AN
2025-06-30 21:05:13 -04:00
parent f60eaa4a1e
commit 6dbf92d71d
2 changed files with 22 additions and 40 deletions

View File

@@ -1,21 +1,16 @@
# nostr/__init__.py
import logging
import traceback
from .client import NostrClient
"""Nostr package exposing :class:`NostrClient` lazily."""
from importlib import import_module
import logging
# Instantiate the logger
logger = logging.getLogger(__name__)
# Initialize the logger for this module
logger = logging.getLogger(__name__) # Correct logger initialization
try:
from .client import NostrClient
logger.info("NostrClient module imported successfully.")
except Exception as e:
logger.error(f"Failed to import NostrClient module: {e}")
logger.error(traceback.format_exc()) # Log full traceback
__all__ = ["NostrClient"]
def __getattr__(name: str):
if name == "NostrClient":
return import_module(".client", __name__).NostrClient
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")