diff --git a/pyproject.toml b/pyproject.toml index 5898827d..381ef9b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/src/pydantic2linkml/gen_linkml.py b/src/pydantic2linkml/gen_linkml.py index 16b5d255..3eeaa686 100644 --- a/src/pydantic2linkml/gen_linkml.py +++ b/src/pydantic2linkml/gen_linkml.py @@ -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 @@ -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: @@ -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 @@ -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)