Skip to content

Commit

Permalink
fix: access literal_values func based on Pydantic version
Browse files Browse the repository at this point in the history
This is put in to support different
version of Pydantic
  • Loading branch information
candleindark committed Nov 27, 2024
1 parent 7b9dbde commit 5b26a14
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 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 @@ -1307,7 +1312,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 5b26a14

Please sign in to comment.