From d870e4d744ee101aad786bf2271e66afdbc5f959 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Oct 2024 11:31:48 -0500 Subject: [PATCH] Add import compat layer to __init__ --- propcache/__init__.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/propcache/__init__.py b/propcache/__init__.py index fe60642..6c2b2e3 100644 --- a/propcache/__init__.py +++ b/propcache/__init__.py @@ -1,6 +1,30 @@ """propcache: An accelerated property cache for Python classes.""" +from typing import TYPE_CHECKING, List + __version__ = "1.0.0" # Imports have moved to `propcache.api` in 1.0.0+. -__all__ = () +# This module is now a facade for the API. +if TYPE_CHECKING: + from .api import cached_property, under_cached_property + +__all__ = ("cached_property", "under_cached_property") + + +def _import_facade(attr: str) -> object: + """Import the public API from the `api` module.""" + if attr in __all__: + from . import api # pylint: disable=import-outside-toplevel + + return getattr(api, attr) + raise AttributeError(f"module 'propcache' has no attribute '{attr}'") + + +def _dir_facade() -> List[str]: + """Include the public API in the module's dir() output.""" + return [*__all__, *globals().keys()] + + +__getattr__ = _import_facade +__dir__ = _dir_facade