Skip to content

fix: read napari's model_fields before the deprecated __fields__ - #146

Merged
tlambert03 merged 4 commits into
pyapp-kit:mainfrom
matthiasschabel:fix/napari-model-fields
Aug 10, 2026
Merged

fix: read napari's model_fields before the deprecated __fields__#146
tlambert03 merged 4 commits into
pyapp-kit:mainfrom
matthiasschabel:fix/napari-model-fields

Conversation

@matthiasschabel

@matthiasschabel matthiasschabel commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

_napari_colormap_param_names() probes pydantic v1's __fields__ before v2's model_fields (src/cmap/_external.py:90-94). v2 keeps __fields__ alive as deprecated so the v2 branch is unreachable.

The first to_napari() call emits PydanticDeprecatedSince20 twice, once for the hasattr probe and once for the read so callers running under -W error get a hard failure. Measured on napari 0.8.0 / pydantic 2.13.4; Colormap.model_fields returns the same names without warning.

Swapping the two branches keeps pydantic v1 working, since it has no model_fields and falls through to __fields__ as before.

The regression test clears the @cache first, otherwise an earlier conversion in the same session has already paid the warning and the test passes vacuously. It carries no filterwarnings marker, so the repo-wide error policy is the assertion.

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

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.70%. Comparing base (0412e56) to head (4f64974).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matthiasschabel
matthiasschabel marked this pull request as ready for review August 9, 2026 23:35
@tlambert03
tlambert03 enabled auto-merge (squash) August 10, 2026 07:14
@tlambert03
tlambert03 merged commit 2c4b86e into pyapp-kit:main Aug 10, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants