deprecation.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import argparse
  15. import sys
  16. import warnings
  17. from typing_extensions import deprecated as deprecated
  18. class CLIDeprecationWarning(DeprecationWarning):
  19. pass
  20. class DeprecatedOptionAction(argparse.Action):
  21. def __call__(self, parser, namespace, values, option_string=None):
  22. assert option_string
  23. warnings.warn(
  24. f"The option `{option_string}` has been deprecated and will be removed in the future. Please refer to the documentation for more details.",
  25. CLIDeprecationWarning,
  26. )
  27. setattr(namespace, self.dest, values)
  28. def warn_deprecated_param(name, new_name=None):
  29. msg = (
  30. f"The parameter `{name}` has been deprecated and will be removed in the future."
  31. )
  32. if new_name is not None:
  33. msg += f" Please use `{new_name}` instead."
  34. warnings.warn(msg, DeprecationWarning, stacklevel=3)