1717 PrivateAttr ,
1818 PlainSerializer ,
1919 BeforeValidator ,
20- RootModel ,
2120)
22- from typing import TYPE_CHECKING , Any , Annotated , TypeAlias
21+ from typing import TYPE_CHECKING , Any , Annotated , TypeAlias , TypeVar
2322
2423from pymatgen .core import Structure
2524from pymatgen .io .vasp .inputs import POTCAR_STATS_PATH , Incar , Kpoints , Poscar , Potcar , PmgVaspPspDirError
@@ -44,33 +43,28 @@ def _msonable_from_str(obj: Any, cls: type[MSONable]) -> MSONable:
4443 return obj
4544
4645
46+ IncarTypeVar = TypeVar ("IncarTypeVar" , Incar , str )
4747IncarType : TypeAlias = Annotated [
48- Incar ,
48+ IncarTypeVar ,
4949 BeforeValidator (lambda x : _msonable_from_str (x , Incar )),
5050 PlainSerializer (lambda x : json .dumps (x .as_dict ()), return_type = str ),
5151]
5252
53+ KpointsTypeVar = TypeVar ("KpointsTypeVar" , Kpoints , str )
5354KpointsType : TypeAlias = Annotated [
54- Kpoints ,
55+ KpointsTypeVar ,
5556 BeforeValidator (lambda x : _msonable_from_str (x , Kpoints )),
5657 PlainSerializer (lambda x : json .dumps (x .as_dict ()), return_type = str ),
5758]
5859
60+ StructureTypeVar = TypeVar ("StructureTypeVar" , Structure , str )
5961StructureType : TypeAlias = Annotated [
60- Structure ,
62+ StructureTypeVar ,
6163 BeforeValidator (lambda x : _msonable_from_str (x , Structure )),
6264 PlainSerializer (lambda x : json .dumps (x .as_dict ()), return_type = str ),
6365]
6466
6567
66- class _MsonStrType (RootModel ):
67- root : str
68-
69-
70- for pmg_obj in (Incar , Kpoints , Structure ):
71- setattr (pmg_obj , "__type_adapter__" , _MsonStrType )
72-
73-
7468class ValidationError (Exception ):
7569 """Define custom exception during validation."""
7670
0 commit comments