When type checking, uses the latest (V2) version of Pydantic
Signed-off-by: Fabio Batista <fabio@atelie.dev.br>
This commit is contained in:
parent
1f95af98ad
commit
c231975efe
|
@ -24,4 +24,4 @@ repos:
|
||||||
types: [ python ]
|
types: [ python ]
|
||||||
args: [ ]
|
args: [ ]
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- "pydantic"
|
- "pydantic~=2.7"
|
||||||
|
|
|
@ -12,17 +12,26 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from cloudevents.exceptions import PydanticFeatureNotInstalled
|
from cloudevents.exceptions import PydanticFeatureNotInstalled
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cloudevents.pydantic.v2 import CloudEvent, from_dict, from_http, from_json
|
||||||
|
else:
|
||||||
from pydantic import VERSION as PYDANTIC_VERSION
|
from pydantic import VERSION as PYDANTIC_VERSION
|
||||||
|
|
||||||
pydantic_major_version = PYDANTIC_VERSION.split(".")[0]
|
pydantic_major_version = PYDANTIC_VERSION.split(".")[0]
|
||||||
if pydantic_major_version == "1":
|
if pydantic_major_version == "1":
|
||||||
from cloudevents.pydantic.v1 import CloudEvent, from_dict, from_http, from_json
|
from cloudevents.pydantic.v1 import (
|
||||||
|
CloudEvent,
|
||||||
|
from_dict,
|
||||||
|
from_http,
|
||||||
|
from_json,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
from cloudevents.pydantic.v2 import ( # type: ignore
|
from cloudevents.pydantic.v2 import (
|
||||||
CloudEvent,
|
CloudEvent,
|
||||||
from_dict,
|
from_dict,
|
||||||
from_http,
|
from_http,
|
||||||
|
|
Loading…
Reference in New Issue