Coverage for src/dynapydantic/version_check.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-06 00:44 +0000

1"""Version checking utilities.""" 

2 

3import pydantic 

4 

5 

6def pydantic_le(version: tuple[int, ...]) -> bool: 

7 """Test whether the pydantic version is <= ``version``.""" 

8 return _pydantic_version() <= version 

9 

10 

11def pydantic_lt(version: tuple[int, ...]) -> bool: 

12 """Test whether the pydantic version is < ``version``.""" 

13 return _pydantic_version() < version 

14 

15 

16def pydantic_ge(version: tuple[int, ...]) -> bool: 

17 """Test whether the pydantic version is >= ``version``.""" 

18 return _pydantic_version() >= version 

19 

20 

21def pydantic_gt(version: tuple[int, ...]) -> bool: 

22 """Test whether the pydantic version is > ``version``.""" 

23 return _pydantic_version() > version 

24 

25 

26_PYDANTIC_VERSION: tuple[int, ...] | None = None 

27 

28 

29def _pydantic_version() -> tuple[int, ...]: 

30 global _PYDANTIC_VERSION # noqa: PLW0603 

31 

32 if _PYDANTIC_VERSION is None: 

33 _PYDANTIC_VERSION = tuple(int(x) for x in pydantic.__version__.split(".")) 

34 

35 return _PYDANTIC_VERSION