Skip to content

Commit

Permalink
port custom validator in Circuits to pydantic 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfried-huss committed Jan 2, 2024
1 parent efd3cf6 commit 02ef0a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions qiskit_aqt_provider/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import io
import typing
from pathlib import Path
from typing import Any, Callable, ClassVar, Iterator, List, Optional, Union
from typing import Any, ClassVar, List, Optional, Union

import platformdirs
import pydantic as pdt
from pydantic import GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
from qiskit import qpy
from qiskit.circuit import QuantumCircuit
from typing_extensions import Self
Expand All @@ -43,8 +45,11 @@ def __init__(self, circuits: List[QuantumCircuit]) -> None:
self.circuits = circuits

@classmethod
def __get_validators__(cls) -> Iterator[Callable[[Any], Any]]: # noqa: D105
yield cls.validate
def __get_pydantic_core_schema__(
cls, source_type: Any, handler: GetCoreSchemaHandler
) -> CoreSchema:
"""Setup custom validator, to turn this class into a pydantic model."""
return core_schema.no_info_plain_validator_function(function=cls.validate)

@classmethod
def validate(cls, value: Union[Self, str]) -> Self:
Expand Down

0 comments on commit 02ef0a2

Please sign in to comment.