Skip to content

Commit

Permalink
Add import compat layer to __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Oct 6, 2024
1 parent f35d343 commit d870e4d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion propcache/__init__.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d870e4d

Please sign in to comment.