Skip to content

[Python] Generated date TypeAdapters fail mypy with Pydantic 2.14 #18156

Closed

Description

@gavinsharp

The generated Python SDK fails its mypy compile check after the dependency lock upgrades Pydantic from 2.13.5 to 2.14.0.

Versions: Fern CLI 5.148.2, fernapi/fern-python-sdk 5.31.1, Python 3.11.15, mypy 1.13.0, Pydantic 2.14.0 (pydantic-core 2.50.0).

The generated core/pydantic_utilities.py contains:

if IS_PYDANTIC_V2:
    _datetime_adapter = pydantic.TypeAdapter(dt.datetime)  # type: ignore[attr-defined]
    _date_adapter = pydantic.TypeAdapter(dt.date)  # type: ignore[attr-defined]

The compile check reports:

error: Need type annotation for "_datetime_adapter" [var-annotated]
error: Need type annotation for "_date_adapter" [var-annotated]

A standalone reproduction requires no API schema:

import datetime as dt
import pydantic

_datetime_adapter = pydantic.TypeAdapter(dt.datetime)
_date_adapter = pydantic.TypeAdapter(dt.date)

Run mypy 1.13.0 on this file with Pydantic 2.14.0 installed: both errors reproduce. In a separate virtual environment with the same mypy version and Pydantic 2.13.5, the file type-checks successfully. The SDK's generated runtime lines are unchanged; the freshly generated dependency lock exposes the failure.

Please generate correctly typed date/datetime adapters that compile against supported Pydantic versions, and add coverage using Pydantic 2.14.0. The wheel and sdist still build and the SDK's runtime tests pass, but this blocks the generated compile job.

Generator upgrade check

The same unannotated declarations are present in the Python 5.34.2 release source (runtime template). Testing those exact declarations with mypy 1.13.0 and Pydantic 2.14.0 reproduces both errors, so that generator update does not contain this annotation fix.

The immediate workaround is to restore the previously working SDK lockfile versions: Pydantic 2.13.5 and pydantic-core 2.46.5.

Activity

  1. dvdaruri-art commented on Oct 9, 2026

    @dvdaruri-art
    Contributor

    It was fixed in a recent release, fernapi/fern-python-sdk 5.39.2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions