Skip to content

pydantic_extra_types.pendulum_dt.DateTime and pendulum.DateTime are not compatible for mypy #210

@SinTh0r4s

Description

@SinTh0r4s

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

We have to use pydantic_extra_types.pendulum_dt.DateTime to use pendulum.DateTime objects in pydantic dataclasses as a workaround, but mypy does not accept a pendulum.DateTime object for a (pydantic) dataclass with a pydantic_extra_types.pendulum_dt.DateTime object. This is not working with the mypy plugin enabled:
pyproject.toml:

[tool.mypy]
plugins = [
  "pydantic.mypy"
]

Example Code

import pendulum
from pydantic.dataclasses import dataclass
from pydantic_extra_types.pendulum_dt import DateTime


@dataclass(config={"strict": True})
class Example:
    datetime: DateTime


instance = pendulum.DateTime(1970, 1, 1)

# Works fine, but mypy throws [args-type]
Example(datetime=instance)
# scratch.py:14: error: Argument "datetime" to "Example" has incompatible type "pendulum.datetime.DateTime"; expected "pydantic_extra_types.pendulum_dt.DateTime"  [arg-type]

Python, Pydantic & OS Version

pydantic version: 2.8.2
        pydantic-core version: 2.20.1
          pydantic-core build: profile=release pgo=true
                 install path: C:\Users\redacted\AppData\Local\pypoetry\Cache\virtualenvs\navkpi-analysis-VIN2uGlr-py3.12\Lib\site-packages\pydantic
               python version: 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
                     platform: Windows-10-10.0.19045-SP0
             related packages: mypy-1.11.1 pydantic-extra-types-2.9.0 typing_extensions-4.12.2
                       commit: unknown

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