From c14e6381446f5bb1ad0dc1e2a3b834e50a407323 Mon Sep 17 00:00:00 2001 From: "Lori A. Burns" Date: Tue, 17 Sep 2024 23:15:35 -0400 Subject: [PATCH] literal schema_name (#337) * Update results.py * Update procedures.py * Update results.py * Update procedures.py * Update procedures.py * Update results.py --- qcelemental/models/procedures.py | 8 +++++++- qcelemental/models/results.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/qcelemental/models/procedures.py b/qcelemental/models/procedures.py index c70146bd..8f6daf5e 100644 --- a/qcelemental/models/procedures.py +++ b/qcelemental/models/procedures.py @@ -1,6 +1,12 @@ from enum import Enum from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple +try: + from typing import Literal +except ImportError: + # remove when minimum py38 + from typing_extensions import Literal + try: from pydantic.v1 import Field, conlist, constr, validator except ImportError: # Will also trap ModuleNotFoundError @@ -58,7 +64,7 @@ class QCInputSpecification(ProtoModel): A compute description for energy, gradient, and Hessian computations used in a geometry optimization. """ - schema_name: constr(strip_whitespace=True, regex=qcschema_input_default) = qcschema_input_default # type: ignore + schema_name: Literal["qcschema_input"] = Field(qcschema_input_default) schema_version: int = 1 driver: DriverEnum = Field(DriverEnum.gradient, description=str(DriverEnum.__doc__)) diff --git a/qcelemental/models/results.py b/qcelemental/models/results.py index df601375..0fd53f21 100644 --- a/qcelemental/models/results.py +++ b/qcelemental/models/results.py @@ -2,6 +2,12 @@ from functools import partial from typing import TYPE_CHECKING, Any, Dict, Optional, Set, Union +try: + from typing import Literal +except ImportError: + # remove when minimum py38 + from typing_extensions import Literal + import numpy as np try: @@ -609,7 +615,7 @@ def __repr_args__(self) -> "ReprArgs": class AtomicResult(AtomicInput): r"""Results from a CMS program execution.""" - schema_name: constr(strip_whitespace=True, regex=r"^(qc\_?schema_output)$") = Field( # type: ignore + schema_name: Literal["qcschema_output"] = Field( qcschema_output_default, description=( f"The QCSchema specification this model conforms to. Explicitly fixed as {qcschema_output_default}."