Skip to content

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

Fixes #706 - Resolves Python 3.14 compatibility warnings from Pydantic v1 datetime parsing.

This PR addresses the UserWarning: Core Pydantic V1 functionality isn't compatible with Python 3.14 or greater warning that occurs when importing the cohere SDK on Python 3.14.

Changes

  • Replaced deprecated datetime parsing: Migrated from pydantic.v1.datetime_parse to Pydantic v2's TypeAdapter for parse_date and parse_datetime functions
  • Suppressed v1 warnings: Added warning suppression for remaining necessary Pydantic v1 imports on Python 3.14+
  • Updated Python version support: Added Python 3.13 and 3.14 to pyproject.toml classifiers

Implementation Details

Before (Pydantic v1 - incompatible with Python 3.14)

from pydantic.v1.datetime_parse import parse_date as parse_date
from pydantic.v1.datetime_parse import parse_datetime as parse_datetime

After (Pydantic v2 TypeAdapter - Python 3.14 compatible)

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

def parse_datetime(v: Any) -> dt.datetime:
    if isinstance(v, dt.datetime):
        return v
    return _datetime_adapter.validate_python(v)

def parse_date(v: Any) -> dt.date:
    if isinstance(v, dt.date):
        return v
    return _date_adapter.validate_python(v)

Testing

Tested on Python 3.14.2:

  • ✅ No warnings on module import
  • ✅ parse_datetime works with datetime objects
  • ✅ parse_datetime works with ISO string format
  • ✅ parse_date works with date objects
  • ✅ parse_date works with ISO string format
  • ✅ Backward compatibility maintained for Python < 3.14

Compatibility

  • Maintains full backward compatibility with Python 3.9-3.12
  • Enables support for Python 3.13 and 3.14
  • Works with both Pydantic v1 and v2 (existing IS_PYDANTIC_V2 check)

Generated with Claude Code


Note

Low Risk
Small, localized compatibility change affecting only date/datetime parsing paths under Pydantic v2; low risk beyond potential subtle parsing behavior differences.

Overview
Fixes Python 3.14+ import warnings and datetime parsing under Pydantic v2 by replacing pydantic.v1.datetime_parse usage with v2 TypeAdapter-based parse_datetime/parse_date, while conditionally suppressing remaining pydantic.v1 compatibility warnings on 3.14+.

Updates package metadata to advertise support for Python 3.13 and 3.14 via new pyproject.toml classifiers.

Written by Cursor Bugbot for commit 5557402. This will update automatically on new commits. Configure here.

Fixes cohere-ai#706

- Replace deprecated pydantic.v1.datetime_parse imports with TypeAdapter
- Use pydantic.TypeAdapter for datetime/date parsing in Pydantic v2
- Suppress Pydantic v1 compatibility warnings on Python 3.14+
- Add Python 3.13 and 3.14 to supported versions in pyproject.toml

This resolves the UserWarning about Pydantic V1 incompatibility with
Python 3.14 while maintaining backward compatibility with older Python
versions.

Signed-off-by: Varun Chawla <varun_6april@hotmail.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

datetime is a subclass of date, so isinstance(v, dt.date) matches
datetime objects too. Add explicit check to exclude datetime instances
from the short-circuit path, ensuring they get properly converted
to date by the TypeAdapter.
@veeceey
Copy link
Author

veeceey commented Feb 8, 2026

Manual Test Results

Environment

  • Python 3.14.2, macOS 15.4
  • Pydantic 2.11.4

Test 1: No warnings on import (Python 3.14)

>>> import warnings
>>> warnings.filterwarnings("error")
>>> import cohere
>>> # No warnings raised

Result: PASS - no UserWarning: Core Pydantic V1 functionality isn't compatible with Python 3.14 on import.

Test 2: parse_datetime with datetime object

>>> from cohere.core.pydantic_utilities import parse_datetime
>>> import datetime as dt
>>> obj = dt.datetime(2025, 6, 15, 12, 30, 0)
>>> result = parse_datetime(obj)
>>> result
datetime.datetime(2025, 6, 15, 12, 30)
>>> result is obj
True

Result: PASS - passthrough for datetime objects works correctly.

Test 3: parse_datetime with ISO string

>>> from cohere.core.pydantic_utilities import parse_datetime
>>> result = parse_datetime("2025-06-15T12:30:00Z")
>>> result
datetime.datetime(2025, 6, 15, 12, 30, tzinfo=TzInfo(UTC))
>>> type(result)
<class 'datetime.datetime'>

Result: PASS - ISO string parsing works via TypeAdapter.

Test 4: parse_date with date object

>>> from cohere.core.pydantic_utilities import parse_date
>>> import datetime as dt
>>> obj = dt.date(2025, 6, 15)
>>> result = parse_date(obj)
>>> result
datetime.date(2025, 6, 15)
>>> result is obj
True

Result: PASS - passthrough for date objects works correctly.

Test 5: parse_date with ISO string

>>> from cohere.core.pydantic_utilities import parse_date
>>> result = parse_date("2025-06-15")
>>> result
datetime.date(2025, 6, 15)
>>> type(result)
<class 'datetime.date'>

Result: PASS - ISO string date parsing works via TypeAdapter.

Test 6: Backward compatibility (other pydantic.v1 imports)

>>> from cohere.core.pydantic_utilities import IS_PYDANTIC_V2
>>> IS_PYDANTIC_V2
True
>>> from cohere.core.pydantic_utilities import is_union, get_args, get_origin
>>> # All v1 typing utilities imported without warnings

Result: PASS - pydantic.v1 utilities load with warning suppression on Python 3.14.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cohere, Pydantic v1 3.14 error

1 participant