_exposed_in.py 693 B

1234567891011121314151617181920
  1. from typing import Callable, TypeVar
  2. F = TypeVar("F")
  3. # Allows one to expose an API in a private submodule publicly as per the definition
  4. # in PyTorch's public api policy.
  5. #
  6. # It is a temporary solution while we figure out if it should be the long-term solution
  7. # or if we should amend PyTorch's public api policy. The concern is that this approach
  8. # may not be very robust because it's not clear what __module__ is used for.
  9. # However, both numpy and jax overwrite the __module__ attribute of their APIs
  10. # without problem, so it seems fine.
  11. def exposed_in(module: str) -> Callable[[F], F]:
  12. def wrapper(fn: F) -> F:
  13. fn.__module__ = module
  14. return fn
  15. return wrapper