Skip to content

Commit ee6693e

Browse files
authored
Merge pull request #10 from candleindark/pydantic-2_10
Add support of Pydantic 2.10
2 parents dcd5b00 + 2a8ac33 commit ee6693e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
]
2929
dependencies = [
3030
"linkml @ git+https://github.com/candleindark/linkml.git@bundle-error",
31-
"pydantic>=2.7,<2.10",
31+
"pydantic~=2.7",
3232
"typer",
3333
]
3434

src/pydantic2linkml/gen_linkml.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
sort_dict,
5555
)
5656

57+
pydantic_version = version.parse(pydantic.__version__)
58+
59+
if pydantic_version >= version.parse("2.10"):
60+
literal_values = _typing_extra.literal_values
61+
else:
62+
literal_values = _typing_extra.all_literal_values
63+
5764
logger = logging.getLogger(__name__)
5865

5966
# Callable to sort a dictionary by its keys case-insensitively
@@ -406,9 +413,7 @@ def _build_schema_type_to_method(
406413
for one of the schema or field types
407414
"""
408415
mapping: dict[CoreSchemaOrFieldType, Callable[[CoreSchemaOrField], None]] = {}
409-
core_schema_types: list[
410-
CoreSchemaOrFieldType
411-
] = _typing_extra.all_literal_values(
416+
core_schema_types: list[CoreSchemaOrFieldType] = literal_values(
412417
CoreSchemaOrFieldType # type: ignore
413418
)
414419
for key in core_schema_types:
@@ -465,6 +470,11 @@ def _attach_note(self, note: str) -> None:
465470
"""
466471
self._slot.notes.append(f"{__package__}: {note}")
467472

473+
if pydantic_version >= version.parse("2.10"):
474+
475+
def _invalid_schema(self, schema: core_schema.InvalidSchema) -> None:
476+
raise TranslationNotImplementedError(schema)
477+
468478
def _any_schema(self, _schema: core_schema.AnySchema) -> None:
469479
"""
470480
Shape the contained slot definition to match any value
@@ -1307,7 +1317,7 @@ def _typed_dict_field_schema(self, schema: core_schema.TypedDictField) -> None:
13071317
def _computed_field_schema(self, schema: core_schema.ComputedField) -> None:
13081318
raise TranslationNotImplementedError(schema)
13091319

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

0 commit comments

Comments
 (0)