fix: read napari's model_fields before the deprecated __fields__ - #146
Merged
tlambert03 merged 4 commits intoAug 10, 2026
Merged
Conversation
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) <noreply@anthropic.com> Reviewed-By: Codex (gpt-5.6-sol, reasoning effort xhigh)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #146 +/- ##
==========================================
+ Coverage 95.61% 95.70% +0.09%
==========================================
Files 168 168
Lines 2188 2188
==========================================
+ Hits 2092 2094 +2
+ Misses 96 94 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
matthiasschabel
marked this pull request as ready for review
August 9, 2026 23:35
tlambert03
enabled auto-merge (squash)
August 10, 2026 07:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_napari_colormap_param_names()probes pydantic v1's__fields__before v2'smodel_fields(src/cmap/_external.py:90-94). v2 keeps__fields__alive as deprecated so the v2 branch is unreachable.The first
to_napari()call emitsPydanticDeprecatedSince20twice, once for thehasattrprobe and once for the read so callers running under-W errorget a hard failure. Measured on napari 0.8.0 / pydantic 2.13.4;Colormap.model_fieldsreturns the same names without warning.Swapping the two branches keeps pydantic v1 working, since it has no
model_fieldsand falls through to__fields__as before.The regression test clears the
@cachefirst, otherwise an earlier conversion in the same session has already paid the warning and the test passes vacuously. It carries nofilterwarningsmarker, so the repo-wideerrorpolicy is the assertion.