Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pydantic/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations as _annotations

from pydantic_core import __version__ as __pydantic_core_version__

__all__ = 'VERSION', 'version_info'

VERSION = '2.10.5'
Expand Down Expand Up @@ -63,6 +65,12 @@ def version_info() -> str:
return '\n'.join('{:>30} {}'.format(k + ':', str(v).replace('\n', ' ')) for k, v in info.items())


def check_pydantic_core_version() -> bool:
"""Check that the installed `pydantic-core` dependency is compatible."""
# Keep this in sync with the version constraint in the `pyproject.toml` dependencies:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we automate this?

Copy link
Copy Markdown
Member Author

@Viicos Viicos Jan 24, 2025

Choose a reason for hiding this comment

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

Probably overkill imo, considering the added test fails if this function was not updated after a pydantic-core version bump

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good, let's merge.

return __pydantic_core_version__ == '2.27.2'


def parse_mypy_version(version: str) -> tuple[int, int, int]:
"""Parse `mypy` string version to a 3-tuple of ints.

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ requires-python = '>=3.9'
dependencies = [
'typing-extensions>=4.12.2',
'annotated-types>=0.6.0',
# Keep this in sync with the version in the `check_pydantic_core_version()` function:
'pydantic-core==2.27.2',
]
dynamic = ['version', 'readme']
Expand Down
6 changes: 5 additions & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from packaging.version import parse as parse_version

import pydantic
from pydantic.version import version_info, version_short
from pydantic.version import check_pydantic_core_version, version_info, version_short


def test_version_info():
Expand Down Expand Up @@ -37,6 +37,10 @@ def test_version_attribute_is_a_string():
assert isinstance(pydantic.__version__, str)


def test_check_pydantic_core_version() -> None:
assert check_pydantic_core_version()


@pytest.mark.parametrize('version,expected', (('2.1', '2.1'), ('2.1.0', '2.1')))
def test_version_short(version, expected):
with patch('pydantic.version.VERSION', version):
Expand Down