Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
SinTh0r4s opened this issue Sep 2, 2024 · 0 comments

Comments

@SinTh0r4s
Copy link

SinTh0r4s commented Sep 2, 2024

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
@Viicos Viicos transferred this issue from pydantic/pydantic Sep 3, 2024
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

No branches or pull requests

1 participant