Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix pydantic deprecation #35

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading