From fbe45761f35143b6c2540147de5c99217bb2f89a Mon Sep 17 00:00:00 2001 From: leavesster <11785335+leavesster@users.noreply.github.com> Date: Sat, 31 Jan 2026 14:27:59 +0800 Subject: [PATCH] feat: add proper deprecation warnings for deprecated APIs Use warnings.warn with DeprecationWarning for deprecated methods: - pkg_dir property: deprecated in favor of pkg_data_dir - send_error method: deprecated in favor of error() This allows users to catch deprecation warnings and migrate their code. --- oocana/oocana/context.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/oocana/oocana/context.py b/oocana/oocana/context.py index 40f4cac..c2e6d6a 100644 --- a/oocana/oocana/context.py +++ b/oocana/oocana/context.py @@ -15,6 +15,7 @@ import os.path import logging import hashlib +import warnings __all__ = ["Context", "HandleDefDict", "BlockJob", "BlockExecuteException"] @@ -241,7 +242,15 @@ def tmp_pkg_dir(self) -> str: @property def pkg_dir(self) -> str: """Deprecated, use pkg_data_dir instead. + + .. deprecated:: 0.18.0 + Use :attr:`pkg_data_dir` instead. """ + warnings.warn( + "pkg_dir is deprecated, use pkg_data_dir instead", + DeprecationWarning, + stacklevel=2 + ) return self.__pkg_data_dir @property @@ -647,10 +656,16 @@ def send_warning(self, warning: str): self.__mainframe.report(self.block_info, {"type": "BlockWarning", "warning": warning}) def send_error(self, error: str): - ''' - deprecated, use error(error) instead. - consider to remove in the future. - ''' + """Send an error message. + + .. deprecated:: 0.18.0 + Use :meth:`error` instead. + """ + warnings.warn( + "send_error is deprecated, use error() instead", + DeprecationWarning, + stacklevel=2 + ) self.error(error) def error(self, error: str):