Skip to content

Commit 821c08c

Browse files
authored
Merge pull request #136 from kddubey/fix-version-checks
Fix #134: compare Pydantic version string correctly
2 parents 7398f29 + fe1166d commit 821c08c

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
license="MIT",
3333
packages=find_packages(),
3434
package_data={"tap": ["py.typed"]},
35-
install_requires=["typing-inspect >= 0.7.1", "docstring-parser >= 0.15"],
35+
install_requires=[
36+
"docstring-parser >= 0.15",
37+
"packaging",
38+
"typing-inspect >= 0.7.1",
39+
],
3640
tests_require=test_requirements,
3741
extras_require={
3842
"dev-no-pydantic": test_requirements,

tap/tapify.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Callable, Dict, List, Optional, Sequence, Type, TypeVar, Union
1111

1212
from docstring_parser import Docstring, parse
13+
from packaging.version import Version
1314

1415
try:
1516
import pydantic
@@ -20,7 +21,7 @@
2021
_PydanticField = type("_PydanticField", (object,), {})
2122
_PYDANTIC_FIELD_TYPES = ()
2223
else:
23-
_IS_PYDANTIC_V1 = pydantic.__version__ < "2.0.0"
24+
_IS_PYDANTIC_V1 = Version(pydantic.__version__) < Version("2.0.0")
2425
from pydantic import BaseModel
2526
from pydantic.fields import FieldInfo as PydanticFieldBaseModel
2627
from pydantic.dataclasses import FieldInfo as PydanticFieldDataclass

tests/test_tapify.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import unittest
1111
from unittest import TestCase
1212

13+
from packaging.version import Version
14+
1315
from tap import tapify
1416

1517

@@ -18,7 +20,7 @@
1820
except ModuleNotFoundError:
1921
_IS_PYDANTIC_V1 = None
2022
else:
21-
_IS_PYDANTIC_V1 = pydantic.__version__ < "2.0.0"
23+
_IS_PYDANTIC_V1 = Version(pydantic.__version__) < Version("2.0.0")
2224

2325

2426
# Suppress prints from SystemExit

tests/test_to_tap_class.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
1111

12+
from packaging.version import Version
1213
import pytest
1314

1415
from tap import to_tap_class, Tap
@@ -20,7 +21,7 @@
2021
except ModuleNotFoundError:
2122
_IS_PYDANTIC_V1 = None
2223
else:
23-
_IS_PYDANTIC_V1 = pydantic.__version__ < "2.0.0"
24+
_IS_PYDANTIC_V1 = Version(pydantic.__version__) < Version("2.0.0")
2425

2526

2627
# To properly test the help message, we need to know how argparse formats it. It changed from 3.8 -> 3.9 -> 3.10

0 commit comments

Comments
 (0)