Skip to content

Commit 205a6a5

Browse files
committed
When type checking, uses the latest (V2) version of Pydantic
Signed-off-by: Fabio Batista <fabio@atelie.dev.br>
1 parent 1f95af9 commit 205a6a5

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

cloudevents/pydantic/__init__.py

Lines changed: 21 additions & 12 deletions
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)