Skip to content

Commit

Permalink
Remove PyObject pydantic type from model type hints (#838)
Browse files Browse the repository at this point in the history
* Remove pyobject type

* Switch to import string type

* Fix import string calls
  • Loading branch information
munrojm authored Sep 27, 2023
1 parent c2fad96 commit dc71e0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions emmet-core/emmet/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import requests
from monty.json import MontyDecoder
from pydantic import field_validator, model_validator, Field
from pydantic.types import PyObject
from pydantic import field_validator, model_validator, Field, ImportString
from pydantic_settings import BaseSettings, SettingsConfigDict

DEFAULT_CONFIG_FILE_PATH = str(Path.home().joinpath(".emmet.json"))
Expand Down Expand Up @@ -121,7 +120,7 @@ class EmmetSettings(BaseSettings):
description="Relative tolerance for kspacing to still be a valid task document",
)

VASP_DEFAULT_INPUT_SETS: Dict[str, PyObject] = Field(
VASP_DEFAULT_INPUT_SETS: Dict[str, ImportString] = Field(
{
"GGA Structure Optimization": "pymatgen.io.vasp.sets.MPRelaxSet",
"GGA+U Structure Optimization": "pymatgen.io.vasp.sets.MPRelaxSet",
Expand Down
6 changes: 3 additions & 3 deletions emmet-core/emmet/core/vasp/validation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import datetime
from typing import Dict, List, Union, Optional, Any
from typing import Dict, List, Union, Optional

import numpy as np
from pydantic import ConfigDict, Field
from pydantic import ConfigDict, Field, ImportString
from pymatgen.core.structure import Structure
from pymatgen.io.vasp.sets import VaspInputSet

Expand Down Expand Up @@ -63,7 +63,7 @@ def from_task_doc(
task_doc: TaskDocument,
kpts_tolerance: float = SETTINGS.VASP_KPTS_TOLERANCE,
kspacing_tolerance: float = SETTINGS.VASP_KSPACING_TOLERANCE,
input_sets: Dict[str, Any] = SETTINGS.VASP_DEFAULT_INPUT_SETS,
input_sets: Dict[str, ImportString] = SETTINGS.VASP_DEFAULT_INPUT_SETS,
LDAU_fields: List[str] = SETTINGS.VASP_CHECKED_LDAU_FIELDS,
max_allowed_scf_gradient: float = SETTINGS.VASP_MAX_SCF_GRADIENT,
potcar_hashes: Optional[Dict[CalcType, Dict[str, str]]] = None,
Expand Down
2 changes: 1 addition & 1 deletion emmet-core/tests/vasp/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_validator(tasks):
validation_docs = [ValidationDoc.from_task_doc(task) for task in tasks]

assert len(validation_docs) == len(tasks)
assert all(doc.valid for doc in validation_docs)
assert all([doc.valid for doc in validation_docs])


def test_computed_entry(tasks):
Expand Down

0 comments on commit dc71e0b

Please sign in to comment.