Skip to content

Commit

Permalink
Merge pull request #10 from candleindark/pydantic-2_10
Browse files Browse the repository at this point in the history
Add support of Pydantic 2.10
  • Loading branch information
candleindark authored Jan 7, 2025
2 parents dcd5b00 + 2a8ac33 commit ee6693e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
]
dependencies = [
"linkml @ git+https://github.com/candleindark/linkml.git@bundle-error",
"pydantic>=2.7,<2.10",
"pydantic~=2.7",
"typer",
]

Expand Down
18 changes: 14 additions & 4 deletions src/pydantic2linkml/gen_linkml.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
sort_dict,
)

pydantic_version = version.parse(pydantic.__version__)

if pydantic_version >= version.parse("2.10"):
literal_values = _typing_extra.literal_values
else:
literal_values = _typing_extra.all_literal_values

logger = logging.getLogger(__name__)

# Callable to sort a dictionary by its keys case-insensitively
Expand Down Expand Up @@ -406,9 +413,7 @@ def _build_schema_type_to_method(
for one of the schema or field types
"""
mapping: dict[CoreSchemaOrFieldType, Callable[[CoreSchemaOrField], None]] = {}
core_schema_types: list[
CoreSchemaOrFieldType
] = _typing_extra.all_literal_values(
core_schema_types: list[CoreSchemaOrFieldType] = literal_values(
CoreSchemaOrFieldType # type: ignore
)
for key in core_schema_types:
Expand Down Expand Up @@ -465,6 +470,11 @@ def _attach_note(self, note: str) -> None:
"""
self._slot.notes.append(f"{__package__}: {note}")

if pydantic_version >= version.parse("2.10"):

def _invalid_schema(self, schema: core_schema.InvalidSchema) -> None:
raise TranslationNotImplementedError(schema)

def _any_schema(self, _schema: core_schema.AnySchema) -> None:
"""
Shape the contained slot definition to match any value
Expand Down Expand Up @@ -1307,7 +1317,7 @@ def _typed_dict_field_schema(self, schema: core_schema.TypedDictField) -> None:
def _computed_field_schema(self, schema: core_schema.ComputedField) -> None:
raise TranslationNotImplementedError(schema)

if version.parse(pydantic.__version__) >= version.parse("2.9"):
if pydantic_version >= version.parse("2.9"):
# Methods define when Pydantic version is 2.9 or later
def _complex_schema(self, schema: core_schema.ComplexSchema) -> None:
raise TranslationNotImplementedError(schema)
Expand Down

0 comments on commit ee6693e

Please sign in to comment.