1# Copyright (c) Meta Platforms, Inc. and affiliates. 2# All rights reserved. 3# 4# This source code is licensed under the BSD-style license found in the 5# LICENSE file in the root directory of this source tree. 6 7"""Decorators used to warn about non-stable APIs.""" 8 9# pyre-strict 10 11from typing import Any, Dict, Optional, Sequence, Type 12 13from typing_extensions import deprecated 14 15__all__ = ["deprecated", "experimental"] 16 17 18class ExperimentalWarning(DeprecationWarning): 19 """Emitted when calling an experimental API. 20 21 Derives from DeprecationWarning so that it is similarly filtered out by 22 default. 23 """ 24 25 def __init__(self, /, *args: Sequence[Any], **kwargs: Dict[str, Any]) -> None: 26 super().__init__(*args, **kwargs) 27 28 29class experimental(deprecated): 30 """Indicates that a class, function or overload is experimental. 31 32 When this decorator is applied to an object, the type checker 33 will generate a diagnostic on usage of the experimental object. 34 """ 35 36 def __init__( 37 self, 38 message: str, 39 /, 40 *, 41 category: Optional[Type[Warning]] = ExperimentalWarning, 42 stacklevel: int = 1, 43 ) -> None: 44 super().__init__(message, category=category, stacklevel=stacklevel) 45