diff --git a/src/prefect/_internal/pydantic/annotations/__init__.py b/src/prefect/_internal/pydantic/annotations/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/src/prefect/_internal/pydantic/annotations/pendulum.py b/src/prefect/_internal/pydantic/annotations/pendulum.py deleted file mode 100644 index b18ee1a13310..000000000000 --- a/src/prefect/_internal/pydantic/annotations/pendulum.py +++ /dev/null @@ -1,78 +0,0 @@ -""" -This file contains compat code to handle pendulum.DateTime objects during jsonschema -generation and validation. -""" - -import typing as t - -import pendulum -from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler -from pydantic.json_schema import JsonSchemaValue -from pydantic_core import core_schema -from typing_extensions import Annotated - - -class _PendulumDateTimeAnnotation: - _pendulum_type: t.Type[ - t.Union[pendulum.DateTime, pendulum.Date, pendulum.Time] - ] = pendulum.DateTime - - _pendulum_types_to_schemas = { - pendulum.DateTime: core_schema.datetime_schema(), - pendulum.Date: core_schema.date_schema(), - pendulum.Duration: core_schema.timedelta_schema(), - } - - @classmethod - def __get_pydantic_core_schema__( - cls, - _source_type: t.Any, - _handler: GetCoreSchemaHandler, - ) -> core_schema.CoreSchema: - def validate_from_str( - value: str, - ) -> t.Union[pendulum.DateTime, pendulum.Date, pendulum.Time]: - return pendulum.parse(value) - - def to_str( - value: t.Union[pendulum.DateTime, pendulum.Date, pendulum.Time], - ) -> str: - return value.isoformat() - - from_str_schema = core_schema.chain_schema( - [ - cls._pendulum_types_to_schemas[cls._pendulum_type], - core_schema.no_info_plain_validator_function(validate_from_str), - ] - ) - - return core_schema.json_or_python_schema( - json_schema=from_str_schema, - python_schema=core_schema.union_schema( - [ - # check if it's an instance first before doing any further work - core_schema.is_instance_schema(cls._pendulum_type), - from_str_schema, - ] - ), - serialization=core_schema.plain_serializer_function_ser_schema(to_str), - ) - - @classmethod - def __get_pydantic_json_schema__( - cls, _core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler - ) -> JsonSchemaValue: - return handler(cls._pendulum_types_to_schemas[cls._pendulum_type]) - - -class _PendulumDateAnnotation(_PendulumDateTimeAnnotation): - _pendulum_type = pendulum.Date - - -class _PendulumDurationAnnotation(_PendulumDateTimeAnnotation): - _pendulum_type = pendulum.Duration - - -PydanticPendulumDateTimeType = Annotated[pendulum.DateTime, _PendulumDateTimeAnnotation] -PydanticPendulumDateType = Annotated[pendulum.Date, _PendulumDateAnnotation] -PydanticPendulumDurationType = Annotated[pendulum.Duration, _PendulumDurationAnnotation] diff --git a/src/prefect/_internal/pydantic/v2_schema.py b/src/prefect/_internal/pydantic/v2_schema.py index c9d7fa08b5e1..1a48c283fa23 100644 --- a/src/prefect/_internal/pydantic/v2_schema.py +++ b/src/prefect/_internal/pydantic/v2_schema.py @@ -2,17 +2,11 @@ import typing import typing as t -import pendulum import pydantic from pydantic import BaseModel as V2BaseModel from pydantic import ConfigDict, PydanticUndefinedAnnotation, create_model from pydantic.type_adapter import TypeAdapter -from prefect._internal.pydantic.annotations.pendulum import ( - PydanticPendulumDateTimeType, - PydanticPendulumDateType, - PydanticPendulumDurationType, -) from prefect._internal.pydantic.schemas import GenerateEmptySchemaForUserClasses @@ -74,14 +68,6 @@ def process_v2_params( type_ = t.Any if param.annotation is inspect._empty else param.annotation - # Replace pendulum type annotations with our own so that they are pydantic compatible - if type_ == pendulum.DateTime: - type_ = PydanticPendulumDateTimeType - if type_ == pendulum.Date: - type_ = PydanticPendulumDateType - if type_ == pendulum.Duration: - type_ = PydanticPendulumDurationType - field = pydantic.Field( default=... if param.default is param.empty else param.default, title=param.name,