Skip to content

Commit

Permalink
Support pydantic v2 using v1 shims (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti authored Aug 28, 2023
1 parent f7ef60f commit 2546b04
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 49 deletions.
6 changes: 5 additions & 1 deletion miio/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from typing import TYPE_CHECKING, Dict, Optional

import click
from pydantic import BaseModel, Field

try:
from pydantic.v1 import BaseModel, Field
except ImportError:
from pydantic import BaseModel, Field

try:
from rich import print as echo
Expand Down
6 changes: 5 additions & 1 deletion miio/devtools/simulators/miiosimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from typing import List, Optional, Union

import click
from pydantic import BaseModel, Field, PrivateAttr

try:
from pydantic.v1 import BaseModel, Field, PrivateAttr
except ImportError:
from pydantic import BaseModel, Field, PrivateAttr
from yaml import safe_load

from miio import PushServer
Expand Down
5 changes: 4 additions & 1 deletion miio/devtools/simulators/miotsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from typing import List, Union

import click
from pydantic import Field, validator

try:
from pydantic.v1 import Field, validator
except ImportError:
from pydantic import Field, validator
from miio import PushServer
from miio.miot_cloud import MiotCloud
from miio.miot_models import DeviceModel, MiotAccess, MiotProperty, MiotService
Expand Down
6 changes: 5 additions & 1 deletion miio/miot_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import appdirs
from micloud.miotspec import MiotSpec
from pydantic import BaseModel, Field

try:
from pydantic.v1 import BaseModel, Field
except ImportError:
from pydantic import BaseModel, Field

from miio import CloudException
from miio.miot_models import DeviceModel
Expand Down
5 changes: 4 additions & 1 deletion miio/miot_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from enum import Enum
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field, PrivateAttr, root_validator
try:
from pydantic.v1 import BaseModel, Field, PrivateAttr, root_validator
except ImportError:
from pydantic import BaseModel, Field, PrivateAttr, root_validator

from .descriptors import (
AccessFlags,
Expand Down
6 changes: 5 additions & 1 deletion miio/tests/test_miot_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from pathlib import Path

import pytest
from pydantic import BaseModel

try:
from pydantic.v1 import BaseModel
except ImportError:
from pydantic import BaseModel

from miio.descriptors import (
AccessFlags,
Expand Down
183 changes: 141 additions & 42 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tqdm = "^4"
micloud = { version = ">=0.6" }
croniter = ">=1"
defusedxml = "^0"
pydantic = "^1"
pydantic = ">=1,<3"
PyYAML = ">=5,<7"

# doc dependencies
Expand Down

0 comments on commit 2546b04

Please sign in to comment.