Skip to content

Commit c231975

Browse files
committed
When type checking, uses the latest (V2) version of Pydantic
Signed-off-by: Fabio Batista <[email protected]>
1 parent 1f95af9 commit c231975

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ repos:
2424
types: [ python ]
2525
args: [ ]
2626
additional_dependencies:
27-
- "pydantic"
27+
- "pydantic~=2.7"

cloudevents/pydantic/__init__.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,31 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
from typing import TYPE_CHECKING
16+
1517
from cloudevents.exceptions import PydanticFeatureNotInstalled
1618

1719
try:
18-
from pydantic import VERSION as PYDANTIC_VERSION
19-
20-
pydantic_major_version = PYDANTIC_VERSION.split(".")[0]
21-
if pydantic_major_version == "1":
22-
from cloudevents.pydantic.v1 import CloudEvent, from_dict, from_http, from_json
23-
20+
if TYPE_CHECKING:
21+
from cloudevents.pydantic.v2 import CloudEvent, from_dict, from_http, from_json
2422
else:
25-
from cloudevents.pydantic.v2 import ( # type: ignore
26-
CloudEvent,
27-
from_dict,
28-
from_http,
29-
from_json,
30-
)
23+
from pydantic import VERSION as PYDANTIC_VERSION
24+
25+
pydantic_major_version = PYDANTIC_VERSION.split(".")[0]
26+
if pydantic_major_version == "1":
27+
from cloudevents.pydantic.v1 import (
28+
CloudEvent,
29+
from_dict,
30+
from_http,
31+
from_json,
32+
)
33+
else:
34+
from cloudevents.pydantic.v2 import (
35+
CloudEvent,
36+
from_dict,
37+
from_http,
38+
from_json,
39+
)
3140

3241
except ImportError: # pragma: no cover # hard to test
3342
raise PydanticFeatureNotInstalled(

0 commit comments

Comments
 (0)