From 2ad16e6fad11e959d3d5ed476fc522651e772ac2 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Thu, 8 Oct 2026 11:45:18 -0400 Subject: [PATCH 1/2] fix: fail tests when srfit calls its own deprecated API Add a pytest filterwarnings rule that turns DeprecationWarnings raised by srfit's own source into errors, and fix the two internal calls it caught: FitRecipe.__init__ (pushFitHook) and initializeRecipe (resultsDictionary). Co-Authored-By: Claude Opus 5.5 --- news/fail-on-internal-deprecations.rst | 28 ++++++++++++++++++++++++++ pyproject.toml | 6 ++++++ src/diffpy/srfit/fitbase/fitrecipe.py | 2 +- src/diffpy/srfit/fitbase/fitresults.py | 7 +++++-- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 news/fail-on-internal-deprecations.rst diff --git a/news/fail-on-internal-deprecations.rst b/news/fail-on-internal-deprecations.rst new file mode 100644 index 00000000..e9637e48 --- /dev/null +++ b/news/fail-on-internal-deprecations.rst @@ -0,0 +1,28 @@ +**Added:** + +* The test suite now fails if srfit's own source code calls one of srfit's + deprecated names, so an internal caller missed during a deprecation is + caught in CI. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Creating a ``FitRecipe`` no longer emits a ``DeprecationWarning`` about + ``pushFitHook``. +* ``initializeRecipe`` now emits only its own ``DeprecationWarning`` instead of + also warning about ``resultsDictionary``. + +**Security:** + +* diff --git a/pyproject.toml b/pyproject.toml index 5535d9c2..54adbdfc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,12 @@ diffpy-srfit = "diffpy.srfit.srfit_app:main" [tool.setuptools.dynamic] dependencies = {file = ["requirements/pip.txt"]} +[tool.pytest.ini_options] +# Fail when srfit source calls one of srfit's own deprecated names. +filterwarnings = [ + "error:'diffpy\\.srfit\\.:DeprecationWarning:diffpy\\.srfit", +] + [tool.codespell] exclude-file = ".codespell/ignore_lines.txt" ignore-words = ".codespell/ignore_words.txt" diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index cc6f6924..596d319e 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -231,7 +231,7 @@ def __init__(self, name="fit"): """ RecipeOrganizer.__init__(self, name) self.fithooks = [] - self.pushFitHook(PrintFitHook()) + self.push_fit_hook(PrintFitHook()) self._restraintlist = [] self._oconstraints = [] self._ready = False diff --git a/src/diffpy/srfit/fitbase/fitresults.py b/src/diffpy/srfit/fitbase/fitresults.py index 6e4b46fd..9bee9a05 100644 --- a/src/diffpy/srfit/fitbase/fitresults.py +++ b/src/diffpy/srfit/fitbase/fitresults.py @@ -849,8 +849,11 @@ def resultsDictionary(results): dict The mapping of result names to their string values. """ - resstr = inputToString(results) + return _parse_results_dictionary(results) + +def _parse_results_dictionary(results): + resstr = inputToString(results) rx = { "f": r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", "n": r"[a-zA-Z_]\w*", @@ -892,7 +895,7 @@ def initializeRecipe(recipe, results): AttributeError If no results can be found in ``results``. """ - mpairs = resultsDictionary(results) + mpairs = _parse_results_dictionary(results) if not mpairs: raise AttributeError("Cannot find results") From 7ad49120f2084a9a573917f491bb1b715c1d0c55 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Thu, 8 Oct 2026 13:07:50 -0400 Subject: [PATCH 2/2] add note about removing private function --- src/diffpy/srfit/fitbase/fitresults.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/diffpy/srfit/fitbase/fitresults.py b/src/diffpy/srfit/fitbase/fitresults.py index 9bee9a05..9d9da031 100644 --- a/src/diffpy/srfit/fitbase/fitresults.py +++ b/src/diffpy/srfit/fitbase/fitresults.py @@ -853,6 +853,8 @@ def resultsDictionary(results): def _parse_results_dictionary(results): + """Remove this function when when resultsDictionary and + initializeRecipe are removed in 4.0.0.""" resstr = inputToString(results) rx = { "f": r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?",