File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -54,12 +54,12 @@ test_thirdparty = [
5454 " napari>=0.4.19" ,
5555 " plotly" ,
5656 " pydantic" ,
57- " pydantic-extra-types" ,
57+ " pydantic-extra-types>=2 " ,
5858 " pygfx" ,
5959 " pytest-qt" ,
6060 " rich" ,
6161 " viscm" ,
62- " vispy" ,
62+ " vispy>=0.14 " ,
6363 " pyqtgraph" ,
6464]
6565dev = [
Original file line number Diff line number Diff line change @@ -663,7 +663,14 @@ def __get_pydantic_core_schema__(
663663 from pydantic_core import core_schema
664664
665665 schema = handler (Any )
666- ser = core_schema .plain_serializer_function_ser_schema (lambda x : x .as_dict ())
666+
667+ def _serialize (obj : Colormap ) -> Any :
668+ if obj .info is not None and obj .info .qualified_name :
669+ # this is a catalog item
670+ return obj .info .qualified_name
671+ return obj .as_dict ()
672+
673+ ser = core_schema .plain_serializer_function_ser_schema (_serialize )
667674 return core_schema .no_info_after_validator_function (
668675 cls ._validate , schema , serialization = ser
669676 )
Original file line number Diff line number Diff line change 1717
1818try :
1919 import pydantic_extra_types .color as pydantic_color
20- except ImportError :
20+ except ( ImportError , NotImplementedError ) :
2121 import pydantic .color as pydantic_color
2222
2323
@@ -60,6 +60,11 @@ class Config:
6060 else :
6161 assert MyModel .parse_raw (serialized ) == obj
6262
63+ # with category colormaps, we only use the qualified name
64+ obj2 = MyModel (color = "red" , colormap = Colormap ("viridis" ))
65+ serialized2 = obj2 .json ()
66+ assert '"colormap":"bids:viridis"' in serialized2
67+
6368
6469def test_psygnal_serialization () -> None :
6570 # support for _json_encode_ is built into psygnal, ... don't need json_encoders
You can’t perform that action at this time.
0 commit comments