Skip to content

Commit 89c8fdc

Browse files
committed
Require Pydantic 2.0+
Required for Python 3.14 support Fixes #454 Fixes #452
1 parent d2956ff commit 89c8fdc

File tree

11 files changed

+223
-204
lines changed

11 files changed

+223
-204
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ requires-python = ">=3.8"
1313
dependencies = [
1414
"httpx>=0.21.0,<1",
1515
"packaging",
16-
"pydantic>1.10.7",
16+
"pydantic>=2.0",
1717
"typing_extensions>=4.5.0",
1818
]
1919

replicate/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Account(Resource):
1717
name: str
1818
"""The name of the account."""
1919

20-
github_url: Optional[str]
20+
github_url: Optional[str] = None
2121
"""The GitHub URL of the account."""
2222

2323

replicate/deployment.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, TypedDict, Union
22

3+
import pydantic
34
from typing_extensions import Unpack, deprecated
45

56
from replicate.account import Account
@@ -13,12 +14,6 @@
1314
)
1415
from replicate.resource import Namespace, Resource
1516

16-
try:
17-
from pydantic import v1 as pydantic # type: ignore
18-
except ImportError:
19-
import pydantic # type: ignore
20-
21-
2217
if TYPE_CHECKING:
2318
from replicate.client import Client
2419
from replicate.prediction import Predictions
@@ -66,7 +61,7 @@ class Release(Resource):
6661
The time the release was created.
6762
"""
6863

69-
created_by: Optional[Account]
64+
created_by: Optional[Account] = None
7065
"""
7166
The account that created the release.
7267
"""
@@ -96,7 +91,7 @@ class Configuration(Resource):
9691
The deployment configuration.
9792
"""
9893

99-
current_release: Optional[Release]
94+
current_release: Optional[Release] = None
10095
"""
10196
The current release of the deployment.
10297
"""

replicate/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class File(Resource):
4141
created_at: str
4242
"""The time the file was created."""
4343

44-
expires_at: Optional[str]
44+
expires_at: Optional[str] = None
4545
"""The time the file will expire."""
4646

4747
urls: Dict[str, str]

replicate/model.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Tuple, Union, overload
22

3+
import pydantic
34
from typing_extensions import NotRequired, TypedDict, Unpack, deprecated
45

56
from replicate.exceptions import ReplicateException
@@ -15,12 +16,6 @@
1516
from replicate.resource import Namespace, Resource
1617
from replicate.version import Version, Versions
1718

18-
try:
19-
from pydantic import v1 as pydantic # type: ignore
20-
except ImportError:
21-
import pydantic # type: ignore
22-
23-
2419
if TYPE_CHECKING:
2520
from replicate.client import Client
2621
from replicate.prediction import Predictions
@@ -48,7 +43,7 @@ class Model(Resource):
4843
The name of the model.
4944
"""
5045

51-
description: Optional[str]
46+
description: Optional[str] = None
5247
"""
5348
The description of the model.
5449
"""
@@ -58,17 +53,17 @@ class Model(Resource):
5853
The visibility of the model. Can be 'public' or 'private'.
5954
"""
6055

61-
github_url: Optional[str]
56+
github_url: Optional[str] = None
6257
"""
6358
The GitHub URL of the model.
6459
"""
6560

66-
paper_url: Optional[str]
61+
paper_url: Optional[str] = None
6762
"""
6863
The URL of the paper related to the model.
6964
"""
7065

71-
license_url: Optional[str]
66+
license_url: Optional[str] = None
7267
"""
7368
The URL of the license for the model.
7469
"""
@@ -78,17 +73,17 @@ class Model(Resource):
7873
The number of runs of the model.
7974
"""
8075

81-
cover_image_url: Optional[str]
76+
cover_image_url: Optional[str] = None
8277
"""
8378
The URL of the cover image for the model.
8479
"""
8580

86-
default_example: Optional[Prediction]
81+
default_example: Optional[Prediction] = None
8782
"""
8883
The default example of the model.
8984
"""
9085

91-
latest_version: Optional[Version]
86+
latest_version: Optional[Version] = None
9287
"""
9388
The latest version of the model.
9489
"""
@@ -137,7 +132,7 @@ def reload(self) -> None:
137132
"""
138133

139134
obj = self._client.models.get(f"{self.owner}/{self.name}")
140-
for name, value in obj.dict().items():
135+
for name, value in obj.model_dump().items():
141136
setattr(self, name, value)
142137

143138

replicate/pagination.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
Union,
1212
)
1313

14-
try:
15-
from pydantic import v1 as pydantic # type: ignore
16-
except ImportError:
17-
import pydantic # type: ignore
14+
import pydantic
1815

1916
from replicate.resource import Resource
2017

replicate/prediction.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
import httpx
20+
import pydantic
2021
from typing_extensions import NotRequired, TypedDict, Unpack
2122

2223
from replicate.exceptions import ModelError, ReplicateError
@@ -27,11 +28,6 @@
2728
from replicate.stream import EventSource
2829
from replicate.version import Version
2930

30-
try:
31-
from pydantic import v1 as pydantic # type: ignore
32-
except ImportError:
33-
import pydantic # type: ignore
34-
3531
if TYPE_CHECKING:
3632
from replicate.client import Client
3733
from replicate.deployment import Deployment
@@ -58,31 +54,31 @@ class Prediction(Resource):
5854
status: Literal["starting", "processing", "succeeded", "failed", "canceled"]
5955
"""The status of the prediction."""
6056

61-
input: Optional[Dict[str, Any]]
57+
input: Optional[Dict[str, Any]] = None
6258
"""The input to the prediction."""
6359

64-
output: Optional[Any]
60+
output: Optional[Any] = None
6561
"""The output of the prediction."""
6662

67-
logs: Optional[str]
63+
logs: Optional[str] = None
6864
"""The logs of the prediction."""
6965

70-
error: Optional[str]
66+
error: Optional[str] = None
7167
"""The error encountered during the prediction, if any."""
7268

73-
metrics: Optional[Dict[str, Any]]
69+
metrics: Optional[Dict[str, Any]] = None
7470
"""Metrics for the prediction."""
7571

76-
created_at: Optional[str]
72+
created_at: Optional[str] = None
7773
"""When the prediction was created."""
7874

79-
started_at: Optional[str]
75+
started_at: Optional[str] = None
8076
"""When the prediction was started."""
8177

82-
completed_at: Optional[str]
78+
completed_at: Optional[str] = None
8379
"""When the prediction was completed, if finished."""
8480

85-
urls: Optional[Dict[str, str]]
81+
urls: Optional[Dict[str, str]] = None
8682
"""
8783
URLs associated with the prediction.
8884
@@ -214,7 +210,7 @@ def cancel(self) -> None:
214210
"""
215211

216212
canceled = self._client.predictions.cancel(self.id)
217-
for name, value in canceled.dict().items():
213+
for name, value in canceled.model_dump().items():
218214
setattr(self, name, value)
219215

220216
async def async_cancel(self) -> None:
@@ -223,7 +219,7 @@ async def async_cancel(self) -> None:
223219
"""
224220

225221
canceled = await self._client.predictions.async_cancel(self.id)
226-
for name, value in canceled.dict().items():
222+
for name, value in canceled.model_dump().items():
227223
setattr(self, name, value)
228224

229225
def reload(self) -> None:
@@ -232,7 +228,7 @@ def reload(self) -> None:
232228
"""
233229

234230
updated = self._client.predictions.get(self.id)
235-
for name, value in updated.dict().items():
231+
for name, value in updated.model_dump().items():
236232
setattr(self, name, value)
237233

238234
async def async_reload(self) -> None:
@@ -241,7 +237,7 @@ async def async_reload(self) -> None:
241237
"""
242238

243239
updated = await self._client.predictions.async_get(self.id)
244-
for name, value in updated.dict().items():
240+
for name, value in updated.model_dump().items():
245241
setattr(self, name, value)
246242

247243
def output_iterator(self) -> Iterator[Any]:

replicate/resource.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import abc
22
from typing import TYPE_CHECKING
33

4-
try:
5-
from pydantic import v1 as pydantic # type: ignore
6-
except ImportError:
7-
import pydantic # type: ignore
4+
import pydantic
85

96
if TYPE_CHECKING:
107
from replicate.client import Client

replicate/stream.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111
)
1212

1313
import httpx
14+
import pydantic
1415
from typing_extensions import Unpack
1516

1617
from replicate import identifier
1718
from replicate.exceptions import ReplicateError
1819
from replicate.helpers import transform_output
1920

20-
try:
21-
from pydantic import v1 as pydantic # type: ignore
22-
except ImportError:
23-
import pydantic # type: ignore
24-
25-
2621
if TYPE_CHECKING:
2722
from replicate.client import Client
2823
from replicate.identifier import ModelVersionIdentifier
@@ -49,7 +44,7 @@ class EventType(Enum):
4944
event: EventType
5045
data: str
5146
id: str
52-
retry: Optional[int]
47+
retry: Optional[int] = None
5348

5449
def __str__(self) -> str:
5550
if self.event == ServerSentEvent.EventType.OUTPUT:

replicate/training.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
overload,
1212
)
1313

14+
import pydantic
1415
from typing_extensions import NotRequired, Unpack
1516

1617
from replicate.helpers import async_encode_json, encode_json
@@ -20,11 +21,6 @@
2021
from replicate.resource import Namespace, Resource
2122
from replicate.version import Version
2223

23-
try:
24-
from pydantic import v1 as pydantic # type: ignore
25-
except ImportError:
26-
import pydantic # type: ignore
27-
2824
if TYPE_CHECKING:
2925
from replicate.client import Client
3026
from replicate.file import FileEncodingStrategy
@@ -46,34 +42,34 @@ class Training(Resource):
4642
version: Union[str, Version]
4743
"""The version of the model used to create the training."""
4844

49-
destination: Optional[str]
45+
destination: Optional[str] = None
5046
"""The model destination of the training."""
5147

5248
status: Literal["starting", "processing", "succeeded", "failed", "canceled"]
5349
"""The status of the training."""
5450

55-
input: Optional[Dict[str, Any]]
51+
input: Optional[Dict[str, Any]] = None
5652
"""The input to the training."""
5753

58-
output: Optional[Any]
54+
output: Optional[Any] = None
5955
"""The output of the training."""
6056

61-
logs: Optional[str]
57+
logs: Optional[str] = None
6258
"""The logs of the training."""
6359

64-
error: Optional[str]
60+
error: Optional[str] = None
6561
"""The error encountered during the training, if any."""
6662

67-
created_at: Optional[str]
63+
created_at: Optional[str] = None
6864
"""When the training was created."""
6965

70-
started_at: Optional[str]
66+
started_at: Optional[str] = None
7167
"""When the training was started."""
7268

73-
completed_at: Optional[str]
69+
completed_at: Optional[str] = None
7470
"""When the training was completed, if finished."""
7571

76-
urls: Optional[Dict[str, str]]
72+
urls: Optional[Dict[str, str]] = None
7773
"""
7874
URLs associated with the training.
7975
@@ -88,7 +84,7 @@ def cancel(self) -> None:
8884
"""
8985

9086
canceled = self._client.trainings.cancel(self.id)
91-
for name, value in canceled.dict().items():
87+
for name, value in canceled.model_dump().items():
9288
setattr(self, name, value)
9389

9490
async def async_cancel(self) -> None:
@@ -97,7 +93,7 @@ async def async_cancel(self) -> None:
9793
"""
9894

9995
canceled = await self._client.trainings.async_cancel(self.id)
100-
for name, value in canceled.dict().items():
96+
for name, value in canceled.model_dump().items():
10197
setattr(self, name, value)
10298

10399
def reload(self) -> None:
@@ -106,7 +102,7 @@ def reload(self) -> None:
106102
"""
107103

108104
updated = self._client.trainings.get(self.id)
109-
for name, value in updated.dict().items():
105+
for name, value in updated.model_dump().items():
110106
setattr(self, name, value)
111107

112108
async def async_reload(self) -> None:
@@ -115,7 +111,7 @@ async def async_reload(self) -> None:
115111
"""
116112

117113
updated = await self._client.trainings.async_get(self.id)
118-
for name, value in updated.dict().items():
114+
for name, value in updated.model_dump().items():
119115
setattr(self, name, value)
120116

121117

0 commit comments

Comments
 (0)