Skip to content

Commit

Permalink
chore: fix pydantic deprecation (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Dariusz Duda <[email protected]>
  • Loading branch information
dariuszd21 authored Aug 7, 2024
1 parent 9ff908d commit 6be0fc3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions craft_grammar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

import abc
import re
from collections.abc import Callable, Iterator
from typing import Any, Generic, TypeVar, get_args, get_origin

import pydantic
from overrides import overrides
from pydantic import ValidationError, ValidationInfo
from pydantic import GetCoreSchemaHandler, ValidationError, ValidationInfo
from pydantic_core import core_schema

_on_pattern = re.compile(r"^on\s+(.+)\s*$")
_to_pattern = re.compile(r"^to\s+(.+)\s*$")
Expand All @@ -41,8 +41,15 @@

class _GrammarBase(abc.ABC):
@classmethod
def __get_validators__(cls) -> Iterator[Callable[[Any, ValidationInfo], Any]]:
yield cls.validate
def __get_pydantic_core_schema__(
cls,
source: type[Any],
handler: GetCoreSchemaHandler,
) -> core_schema.CoreSchema:
return core_schema.with_info_after_validator_function(
cls.validate,
core_schema.any_schema(),
)

@classmethod
@abc.abstractmethod
Expand Down

0 comments on commit 6be0fc3

Please sign in to comment.