Skip to content

Python 3.14 compatibility: replace pydantic.v1 imports in _base_compat.py #107

@clemlesne

Description

@clemlesne

Problem

On Python 3.14 (including free-threaded 3.14t), importing zhipuai emits:

/zhipuai/core/_base_compat.py:48: UserWarning: Core Pydantic V1 functionality isn't compatible with Python 3.14 or greater.
  from pydantic.v1.typing import (

Pydantic has officially stated that pydantic.v1 is not supported on Python 3.14+. This is currently a warning but will likely break in a future pydantic release.

Root cause

zhipuai/core/_base_compat.py lines 48-55 import from pydantic.v1 when pydantic v2 is detected:

if PYDANTIC_V2:
    from pydantic.v1.typing import (
        get_args as get_args,
        is_union as is_union,
        get_origin as get_origin,
        is_typeddict as is_typeddict,
        is_literal_type as is_literal_type,
    )
    from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime

Suggested fix

All these functions have stdlib equivalents available since Python 3.8-3.12:

pydantic.v1 import stdlib replacement
get_args typing.get_args
get_origin typing.get_origin
is_union typing.get_origin(tp) is Union or isinstance(tp, types.UnionType)
is_literal_type typing.get_origin(tp) is Literal
is_typeddict typing.is_typeddict (3.12+) or typing_extensions.is_typeddict
parse_date / parse_datetime manual parsing or dateutil.parser

This is the only file in the package that references pydantic.v1.

Environment

  • Python 3.14t (free-threaded)
  • pydantic 2.12.5
  • zhipuai 2.1.5.20250825

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