-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
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
adasium, dronir, perfa-funnel and BryceBeagle
Metadata
Metadata
Assignees
Labels
No labels