Skip to content

Commit 684de5a

Browse files
authored
Use pydantic.dataclasses.dataclass instead of dataclasses.dataclass (#29)
Motivation -- - `dataclasses.dataclass` supports typing, but do not validate. - `pydantic.dataclasses.dataclass` is a drop-in replacement for `dataclasses.dataclass` with **validation**. References -- - https://pydantic-docs.helpmanual.io/usage/dataclasses/ - https://pydantic-docs.helpmanual.io/
1 parent 9b3a3f8 commit 684de5a

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

Diff for: centraldogma/data/change.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass
1514
from enum import Enum
1615
from typing import Optional, Any
1716

1817
from dataclasses_json import dataclass_json
18+
from pydantic.dataclasses import dataclass
1919

2020

2121
class ChangeType(Enum):

Diff for: centraldogma/data/commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass
1514
from typing import Optional
1615

1716
from dataclasses_json import dataclass_json
17+
from pydantic.dataclasses import dataclass
1818

1919

2020
@dataclass_json

Diff for: centraldogma/data/content.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass
1514
from typing import Any, Optional
1615

1716
from dataclasses_json import dataclass_json
17+
from pydantic.dataclasses import dataclass
1818

1919

2020
@dataclass_json

Diff for: centraldogma/data/creator.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass
15-
1614
from dataclasses_json import dataclass_json
15+
from pydantic.dataclasses import dataclass
1716

1817

1918
@dataclass_json

Diff for: centraldogma/data/project.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass, field
14+
from dataclasses import field
1515
from datetime import datetime
1616
from typing import Optional
1717

1818
from dataclasses_json import LetterCase, config, dataclass_json
1919
from dateutil import parser
2020
from marshmallow import fields
21+
from pydantic.dataclasses import dataclass
2122

22-
from centraldogma.data.constants import DATE_FORMAT_ISO8601
2323
from centraldogma.data.creator import Creator
2424

2525

Diff for: centraldogma/data/push_result.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass, field
14+
from dataclasses import field
1515
from datetime import datetime
1616

1717
from dataclasses_json import LetterCase, config, dataclass_json
1818
from marshmallow import fields
1919
from dateutil import parser
20+
from pydantic.dataclasses import dataclass
2021

2122

2223
@dataclass_json(letter_case=LetterCase.CAMEL)

Diff for: centraldogma/data/repository.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from dataclasses import dataclass, field
14+
from dataclasses import field
1515
from datetime import datetime
1616
from typing import Optional
1717

1818
from dataclasses_json import LetterCase, config, dataclass_json
1919
from dateutil import parser
2020
from marshmallow import fields
21+
from pydantic.dataclasses import dataclass
2122

2223
from centraldogma.data.creator import Creator
2324

Diff for: centraldogma/data/revision.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414
from __future__ import annotations
1515

16-
from dataclasses import dataclass
16+
from pydantic.dataclasses import dataclass
1717

1818

1919
@dataclass

Diff for: requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dataclasses-json
22
httpx[http2]
33
marshmallow
4+
pydantic
45
python-dateutil
56

67
# Dev dependencies

0 commit comments

Comments
 (0)