From 52b428e1ff480f77ac3fbc69718e7c278398574c Mon Sep 17 00:00:00 2001 From: Matthias Schabel Date: Sun, 9 Aug 2026 14:15:28 -0700 Subject: [PATCH 1/2] fix: read napari's model_fields before the deprecated __fields__ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pydantic v2 keeps `__fields__` alive as a deprecated class property, so probing it first meant the v2 branch never ran and the first to_napari() call in a process emitted a PydanticDeprecatedSince20 warning — an error for callers running under -W error. Swapping the two branches leaves pydantic v1 working: it has no model_fields, so it falls through to __fields__ as before. Co-Authored-By: Claude Opus 5 (1M context) Reviewed-By: Codex (gpt-5.6-sol, reasoning effort xhigh) --- src/cmap/_external.py | 6 +++--- tests/test_third_party.py | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cmap/_external.py b/src/cmap/_external.py index cb941c9c0..76aaedc4c 100644 --- a/src/cmap/_external.py +++ b/src/cmap/_external.py @@ -87,10 +87,10 @@ def to_plotly(cm: Colormap) -> list[list[float | str]]: def _napari_colormap_param_names() -> set[str]: from napari.utils.colormaps import Colormap - if hasattr(Colormap, "__fields__"): - return set(Colormap.__fields__) - elif hasattr(Colormap, "model_fields"): + if hasattr(Colormap, "model_fields"): return set(Colormap.model_fields) + elif hasattr(Colormap, "__fields__"): + return set(Colormap.__fields__) return set() diff --git a/tests/test_third_party.py b/tests/test_third_party.py index 66c2a9759..d034c9245 100644 --- a/tests/test_third_party.py +++ b/tests/test_third_party.py @@ -73,6 +73,15 @@ def test_napari(qapp: "QApplication") -> None: v.close() +def test_napari_no_deprecated_field_access() -> None: + pytest.importorskip("napari") + from cmap._external import _napari_colormap_param_names + + # the names are cached, so an earlier conversion may already have paid the warning + _napari_colormap_param_names.cache_clear() + assert CMAP.to_napari() is not None + + @pytest.mark.skipif( sys.platform == "darwin" and sys.version_info >= (3, 13), reason="not yet working upstream", From c0991c22eb6d7eb27b0da55f638aabe24c44c0ea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2026 07:14:11 +0000 Subject: [PATCH 2/2] style(pre-commit.ci): auto fixes [...] --- tests/test_third_party.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_third_party.py b/tests/test_third_party.py index 1f2ab7513..a161dac75 100644 --- a/tests/test_third_party.py +++ b/tests/test_third_party.py @@ -81,7 +81,7 @@ def test_napari_no_deprecated_field_access() -> None: _napari_colormap_param_names.cache_clear() assert CMAP.to_napari() is not None - + @pytest.mark.filterwarnings("ignore") def test_napari_extreme_colors() -> None: # nan_color/low_color/high_color were added in napari 0.6.1