runwayml 3.11.0__tar.gz → 3.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. runwayml-3.12.0/.release-please-manifest.json +3 -0
  2. {runwayml-3.11.0 → runwayml-3.12.0}/CHANGELOG.md +8 -0
  3. {runwayml-3.11.0 → runwayml-3.12.0}/PKG-INFO +1 -1
  4. {runwayml-3.11.0 → runwayml-3.12.0}/pyproject.toml +1 -1
  5. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_base_client.py +3 -3
  6. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_compat.py +48 -48
  7. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_models.py +40 -40
  8. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/__init__.py +8 -2
  9. runwayml-3.12.0/src/runwayml/_utils/_compat.py +45 -0
  10. runwayml-3.12.0/src/runwayml/_utils/_datetime_parse.py +136 -0
  11. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_transform.py +5 -1
  12. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_typing.py +1 -1
  13. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_utils.py +0 -1
  14. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_version.py +1 -1
  15. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_models.py +24 -24
  16. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_transform.py +8 -8
  17. runwayml-3.12.0/tests/test_utils/test_datetime_parse.py +110 -0
  18. {runwayml-3.11.0 → runwayml-3.12.0}/tests/utils.py +4 -4
  19. runwayml-3.11.0/.release-please-manifest.json +0 -3
  20. {runwayml-3.11.0 → runwayml-3.12.0}/.gitignore +0 -0
  21. {runwayml-3.11.0 → runwayml-3.12.0}/CONTRIBUTING.md +0 -0
  22. {runwayml-3.11.0 → runwayml-3.12.0}/LICENSE +0 -0
  23. {runwayml-3.11.0 → runwayml-3.12.0}/README.md +0 -0
  24. {runwayml-3.11.0 → runwayml-3.12.0}/SECURITY.md +0 -0
  25. {runwayml-3.11.0 → runwayml-3.12.0}/api.md +0 -0
  26. {runwayml-3.11.0 → runwayml-3.12.0}/bin/check-release-environment +0 -0
  27. {runwayml-3.11.0 → runwayml-3.12.0}/bin/publish-pypi +0 -0
  28. {runwayml-3.11.0 → runwayml-3.12.0}/examples/.keep +0 -0
  29. {runwayml-3.11.0 → runwayml-3.12.0}/examples/generate_image.py +0 -0
  30. {runwayml-3.11.0 → runwayml-3.12.0}/mypy.ini +0 -0
  31. {runwayml-3.11.0 → runwayml-3.12.0}/noxfile.py +0 -0
  32. {runwayml-3.11.0 → runwayml-3.12.0}/release-please-config.json +0 -0
  33. {runwayml-3.11.0 → runwayml-3.12.0}/requirements-dev.lock +0 -0
  34. {runwayml-3.11.0 → runwayml-3.12.0}/requirements.lock +0 -0
  35. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/__init__.py +0 -0
  36. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_client.py +0 -0
  37. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_constants.py +0 -0
  38. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_exceptions.py +0 -0
  39. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_files.py +0 -0
  40. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_qs.py +0 -0
  41. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_resource.py +0 -0
  42. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_response.py +0 -0
  43. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_streaming.py +0 -0
  44. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_types.py +0 -0
  45. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_logs.py +0 -0
  46. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_proxy.py +0 -0
  47. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_reflection.py +0 -0
  48. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_resources_proxy.py +0 -0
  49. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_streams.py +0 -0
  50. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/_utils/_sync.py +0 -0
  51. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/lib/.keep +0 -0
  52. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/lib/polling.py +0 -0
  53. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/py.typed +0 -0
  54. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/__init__.py +0 -0
  55. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/character_performance.py +0 -0
  56. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/image_to_video.py +0 -0
  57. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/organization.py +0 -0
  58. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/tasks.py +0 -0
  59. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/text_to_image.py +0 -0
  60. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/video_to_video.py +0 -0
  61. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/resources/video_upscale.py +0 -0
  62. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/__init__.py +0 -0
  63. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/character_performance_create_params.py +0 -0
  64. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/character_performance_create_response.py +0 -0
  65. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/image_to_video_create_params.py +0 -0
  66. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/image_to_video_create_response.py +0 -0
  67. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/organization_retrieve_response.py +0 -0
  68. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/organization_retrieve_usage_params.py +0 -0
  69. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/organization_retrieve_usage_response.py +0 -0
  70. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/task_retrieve_response.py +0 -0
  71. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/text_to_image_create_params.py +0 -0
  72. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/text_to_image_create_response.py +0 -0
  73. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/video_to_video_create_params.py +0 -0
  74. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/video_to_video_create_response.py +0 -0
  75. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/video_upscale_create_params.py +0 -0
  76. {runwayml-3.11.0 → runwayml-3.12.0}/src/runwayml/types/video_upscale_create_response.py +0 -0
  77. {runwayml-3.11.0 → runwayml-3.12.0}/tests/__init__.py +0 -0
  78. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/__init__.py +0 -0
  79. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_character_performance.py +0 -0
  80. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_image_to_video.py +0 -0
  81. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_organization.py +0 -0
  82. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_tasks.py +0 -0
  83. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_text_to_image.py +0 -0
  84. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_video_to_video.py +0 -0
  85. {runwayml-3.11.0 → runwayml-3.12.0}/tests/api_resources/test_video_upscale.py +0 -0
  86. {runwayml-3.11.0 → runwayml-3.12.0}/tests/conftest.py +0 -0
  87. {runwayml-3.11.0 → runwayml-3.12.0}/tests/sample_file.txt +0 -0
  88. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_client.py +0 -0
  89. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_deepcopy.py +0 -0
  90. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_extract_files.py +0 -0
  91. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_files.py +0 -0
  92. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_qs.py +0 -0
  93. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_required_args.py +0 -0
  94. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_response.py +0 -0
  95. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_streaming.py +0 -0
  96. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_utils/test_proxy.py +0 -0
  97. {runwayml-3.11.0 → runwayml-3.12.0}/tests/test_utils/test_typing.py +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "3.12.0"
3
+ }
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.12.0 (2025-09-04)
4
+
5
+ Full Changelog: [v3.11.0...v3.12.0](https://github.com/runwayml/sdk-python/compare/v3.11.0...v3.12.0)
6
+
7
+ ### Features
8
+
9
+ * improve future compat with pydantic v3 ([9207df5](https://github.com/runwayml/sdk-python/commit/9207df5599921825e8138ddbe006f004c579c875))
10
+
3
11
  ## 3.11.0 (2025-09-03)
4
12
 
5
13
  Full Changelog: [v3.10.3...v3.11.0](https://github.com/runwayml/sdk-python/compare/v3.10.3...v3.11.0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: runwayml
3
- Version: 3.11.0
3
+ Version: 3.12.0
4
4
  Summary: The official Python library for the runwayml API
5
5
  Project-URL: Homepage, https://github.com/runwayml/sdk-python
6
6
  Project-URL: Repository, https://github.com/runwayml/sdk-python
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "runwayml"
3
- version = "3.11.0"
3
+ version = "3.12.0"
4
4
  description = "The official Python library for the runwayml API"
5
5
  dynamic = ["readme"]
6
6
  license = "Apache-2.0"
@@ -59,7 +59,7 @@ from ._types import (
59
59
  ModelBuilderProtocol,
60
60
  )
61
61
  from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
62
- from ._compat import PYDANTIC_V2, model_copy, model_dump
62
+ from ._compat import PYDANTIC_V1, model_copy, model_dump
63
63
  from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
64
64
  from ._response import (
65
65
  APIResponse,
@@ -232,7 +232,7 @@ class BaseSyncPage(BasePage[_T], Generic[_T]):
232
232
  model: Type[_T],
233
233
  options: FinalRequestOptions,
234
234
  ) -> None:
235
- if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
235
+ if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
236
236
  self.__pydantic_private__ = {}
237
237
 
238
238
  self._model = model
@@ -320,7 +320,7 @@ class BaseAsyncPage(BasePage[_T], Generic[_T]):
320
320
  client: AsyncAPIClient,
321
321
  options: FinalRequestOptions,
322
322
  ) -> None:
323
- if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
323
+ if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
324
324
  self.__pydantic_private__ = {}
325
325
 
326
326
  self._model = model
@@ -12,14 +12,13 @@ from ._types import IncEx, StrBytesIntFloat
12
12
  _T = TypeVar("_T")
13
13
  _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
14
 
15
- # --------------- Pydantic v2 compatibility ---------------
15
+ # --------------- Pydantic v2, v3 compatibility ---------------
16
16
 
17
17
  # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
18
  # pyright: reportIncompatibleMethodOverride=false
19
19
 
20
- PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
20
+ PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
21
21
 
22
- # v1 re-exports
23
22
  if TYPE_CHECKING:
24
23
 
25
24
  def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
@@ -44,90 +43,92 @@ if TYPE_CHECKING:
44
43
  ...
45
44
 
46
45
  else:
47
- if PYDANTIC_V2:
48
- from pydantic.v1.typing import (
46
+ # v1 re-exports
47
+ if PYDANTIC_V1:
48
+ from pydantic.typing import (
49
49
  get_args as get_args,
50
50
  is_union as is_union,
51
51
  get_origin as get_origin,
52
52
  is_typeddict as is_typeddict,
53
53
  is_literal_type as is_literal_type,
54
54
  )
55
- from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
55
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
56
  else:
57
- from pydantic.typing import (
57
+ from ._utils import (
58
58
  get_args as get_args,
59
59
  is_union as is_union,
60
60
  get_origin as get_origin,
61
+ parse_date as parse_date,
61
62
  is_typeddict as is_typeddict,
63
+ parse_datetime as parse_datetime,
62
64
  is_literal_type as is_literal_type,
63
65
  )
64
- from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
65
66
 
66
67
 
67
68
  # refactored config
68
69
  if TYPE_CHECKING:
69
70
  from pydantic import ConfigDict as ConfigDict
70
71
  else:
71
- if PYDANTIC_V2:
72
- from pydantic import ConfigDict
73
- else:
72
+ if PYDANTIC_V1:
74
73
  # TODO: provide an error message here?
75
74
  ConfigDict = None
75
+ else:
76
+ from pydantic import ConfigDict as ConfigDict
76
77
 
77
78
 
78
79
  # renamed methods / properties
79
80
  def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
80
- if PYDANTIC_V2:
81
- return model.model_validate(value)
82
- else:
81
+ if PYDANTIC_V1:
83
82
  return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
83
+ else:
84
+ return model.model_validate(value)
84
85
 
85
86
 
86
87
  def field_is_required(field: FieldInfo) -> bool:
87
- if PYDANTIC_V2:
88
- return field.is_required()
89
- return field.required # type: ignore
88
+ if PYDANTIC_V1:
89
+ return field.required # type: ignore
90
+ return field.is_required()
90
91
 
91
92
 
92
93
  def field_get_default(field: FieldInfo) -> Any:
93
94
  value = field.get_default()
94
- if PYDANTIC_V2:
95
- from pydantic_core import PydanticUndefined
96
-
97
- if value == PydanticUndefined:
98
- return None
95
+ if PYDANTIC_V1:
99
96
  return value
97
+ from pydantic_core import PydanticUndefined
98
+
99
+ if value == PydanticUndefined:
100
+ return None
100
101
  return value
101
102
 
102
103
 
103
104
  def field_outer_type(field: FieldInfo) -> Any:
104
- if PYDANTIC_V2:
105
- return field.annotation
106
- return field.outer_type_ # type: ignore
105
+ if PYDANTIC_V1:
106
+ return field.outer_type_ # type: ignore
107
+ return field.annotation
107
108
 
108
109
 
109
110
  def get_model_config(model: type[pydantic.BaseModel]) -> Any:
110
- if PYDANTIC_V2:
111
- return model.model_config
112
- return model.__config__ # type: ignore
111
+ if PYDANTIC_V1:
112
+ return model.__config__ # type: ignore
113
+ return model.model_config
113
114
 
114
115
 
115
116
  def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
116
- if PYDANTIC_V2:
117
- return model.model_fields
118
- return model.__fields__ # type: ignore
117
+ if PYDANTIC_V1:
118
+ return model.__fields__ # type: ignore
119
+ return model.model_fields
119
120
 
120
121
 
121
122
  def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
122
- if PYDANTIC_V2:
123
- return model.model_copy(deep=deep)
124
- return model.copy(deep=deep) # type: ignore
123
+ if PYDANTIC_V1:
124
+ return model.copy(deep=deep) # type: ignore
125
+ return model.model_copy(deep=deep)
125
126
 
126
127
 
127
128
  def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
128
- if PYDANTIC_V2:
129
- return model.model_dump_json(indent=indent)
130
- return model.json(indent=indent) # type: ignore
129
+ if PYDANTIC_V1:
130
+ return model.json(indent=indent) # type: ignore
131
+ return model.model_dump_json(indent=indent)
131
132
 
132
133
 
133
134
  def model_dump(
@@ -139,14 +140,14 @@ def model_dump(
139
140
  warnings: bool = True,
140
141
  mode: Literal["json", "python"] = "python",
141
142
  ) -> dict[str, Any]:
142
- if PYDANTIC_V2 or hasattr(model, "model_dump"):
143
+ if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
143
144
  return model.model_dump(
144
145
  mode=mode,
145
146
  exclude=exclude,
146
147
  exclude_unset=exclude_unset,
147
148
  exclude_defaults=exclude_defaults,
148
149
  # warnings are not supported in Pydantic v1
149
- warnings=warnings if PYDANTIC_V2 else True,
150
+ warnings=True if PYDANTIC_V1 else warnings,
150
151
  )
151
152
  return cast(
152
153
  "dict[str, Any]",
@@ -159,9 +160,9 @@ def model_dump(
159
160
 
160
161
 
161
162
  def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
162
- if PYDANTIC_V2:
163
- return model.model_validate(data)
164
- return model.parse_obj(data) # pyright: ignore[reportDeprecated]
163
+ if PYDANTIC_V1:
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+ return model.model_validate(data)
165
166
 
166
167
 
167
168
  # generic models
@@ -170,17 +171,16 @@ if TYPE_CHECKING:
170
171
  class GenericModel(pydantic.BaseModel): ...
171
172
 
172
173
  else:
173
- if PYDANTIC_V2:
174
+ if PYDANTIC_V1:
175
+ import pydantic.generics
176
+
177
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
178
+ else:
174
179
  # there no longer needs to be a distinction in v2 but
175
180
  # we still have to create our own subclass to avoid
176
181
  # inconsistent MRO ordering errors
177
182
  class GenericModel(pydantic.BaseModel): ...
178
183
 
179
- else:
180
- import pydantic.generics
181
-
182
- class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
183
-
184
184
 
185
185
  # cached properties
186
186
  if TYPE_CHECKING:
@@ -50,7 +50,7 @@ from ._utils import (
50
50
  strip_annotated_type,
51
51
  )
52
52
  from ._compat import (
53
- PYDANTIC_V2,
53
+ PYDANTIC_V1,
54
54
  ConfigDict,
55
55
  GenericModel as BaseGenericModel,
56
56
  get_args,
@@ -81,11 +81,7 @@ class _ConfigProtocol(Protocol):
81
81
 
82
82
 
83
83
  class BaseModel(pydantic.BaseModel):
84
- if PYDANTIC_V2:
85
- model_config: ClassVar[ConfigDict] = ConfigDict(
86
- extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
87
- )
88
- else:
84
+ if PYDANTIC_V1:
89
85
 
90
86
  @property
91
87
  @override
@@ -95,6 +91,10 @@ class BaseModel(pydantic.BaseModel):
95
91
 
96
92
  class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
97
93
  extra: Any = pydantic.Extra.allow # type: ignore
94
+ else:
95
+ model_config: ClassVar[ConfigDict] = ConfigDict(
96
+ extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
97
+ )
98
98
 
99
99
  def to_dict(
100
100
  self,
@@ -215,25 +215,25 @@ class BaseModel(pydantic.BaseModel):
215
215
  if key not in model_fields:
216
216
  parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
217
217
 
218
- if PYDANTIC_V2:
219
- _extra[key] = parsed
220
- else:
218
+ if PYDANTIC_V1:
221
219
  _fields_set.add(key)
222
220
  fields_values[key] = parsed
221
+ else:
222
+ _extra[key] = parsed
223
223
 
224
224
  object.__setattr__(m, "__dict__", fields_values)
225
225
 
226
- if PYDANTIC_V2:
227
- # these properties are copied from Pydantic's `model_construct()` method
228
- object.__setattr__(m, "__pydantic_private__", None)
229
- object.__setattr__(m, "__pydantic_extra__", _extra)
230
- object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
231
- else:
226
+ if PYDANTIC_V1:
232
227
  # init_private_attributes() does not exist in v2
233
228
  m._init_private_attributes() # type: ignore
234
229
 
235
230
  # copied from Pydantic v1's `construct()` method
236
231
  object.__setattr__(m, "__fields_set__", _fields_set)
232
+ else:
233
+ # these properties are copied from Pydantic's `model_construct()` method
234
+ object.__setattr__(m, "__pydantic_private__", None)
235
+ object.__setattr__(m, "__pydantic_extra__", _extra)
236
+ object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
237
237
 
238
238
  return m
239
239
 
@@ -243,7 +243,7 @@ class BaseModel(pydantic.BaseModel):
243
243
  # although not in practice
244
244
  model_construct = construct
245
245
 
246
- if not PYDANTIC_V2:
246
+ if PYDANTIC_V1:
247
247
  # we define aliases for some of the new pydantic v2 methods so
248
248
  # that we can just document these methods without having to specify
249
249
  # a specific pydantic version as some users may not know which
@@ -363,10 +363,10 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
363
363
  if value is None:
364
364
  return field_get_default(field)
365
365
 
366
- if PYDANTIC_V2:
367
- type_ = field.annotation
368
- else:
366
+ if PYDANTIC_V1:
369
367
  type_ = cast(type, field.outer_type_) # type: ignore
368
+ else:
369
+ type_ = field.annotation # type: ignore
370
370
 
371
371
  if type_ is None:
372
372
  raise RuntimeError(f"Unexpected field type is None for {key}")
@@ -375,7 +375,7 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
375
375
 
376
376
 
377
377
  def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
378
- if not PYDANTIC_V2:
378
+ if PYDANTIC_V1:
379
379
  # TODO
380
380
  return None
381
381
 
@@ -628,30 +628,30 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
628
628
  for variant in get_args(union):
629
629
  variant = strip_annotated_type(variant)
630
630
  if is_basemodel_type(variant):
631
- if PYDANTIC_V2:
632
- field = _extract_field_schema_pv2(variant, discriminator_field_name)
633
- if not field:
631
+ if PYDANTIC_V1:
632
+ field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
633
+ if not field_info:
634
634
  continue
635
635
 
636
636
  # Note: if one variant defines an alias then they all should
637
- discriminator_alias = field.get("serialization_alias")
638
-
639
- field_schema = field["schema"]
637
+ discriminator_alias = field_info.alias
640
638
 
641
- if field_schema["type"] == "literal":
642
- for entry in cast("LiteralSchema", field_schema)["expected"]:
639
+ if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
640
+ for entry in get_args(annotation):
643
641
  if isinstance(entry, str):
644
642
  mapping[entry] = variant
645
643
  else:
646
- field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
647
- if not field_info:
644
+ field = _extract_field_schema_pv2(variant, discriminator_field_name)
645
+ if not field:
648
646
  continue
649
647
 
650
648
  # Note: if one variant defines an alias then they all should
651
- discriminator_alias = field_info.alias
649
+ discriminator_alias = field.get("serialization_alias")
652
650
 
653
- if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
654
- for entry in get_args(annotation):
651
+ field_schema = field["schema"]
652
+
653
+ if field_schema["type"] == "literal":
654
+ for entry in cast("LiteralSchema", field_schema)["expected"]:
655
655
  if isinstance(entry, str):
656
656
  mapping[entry] = variant
657
657
 
@@ -714,7 +714,7 @@ else:
714
714
  pass
715
715
 
716
716
 
717
- if PYDANTIC_V2:
717
+ if not PYDANTIC_V1:
718
718
  from pydantic import TypeAdapter as _TypeAdapter
719
719
 
720
720
  _CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))
@@ -782,12 +782,12 @@ class FinalRequestOptions(pydantic.BaseModel):
782
782
  json_data: Union[Body, None] = None
783
783
  extra_json: Union[AnyMapping, None] = None
784
784
 
785
- if PYDANTIC_V2:
786
- model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
787
- else:
785
+ if PYDANTIC_V1:
788
786
 
789
787
  class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
790
788
  arbitrary_types_allowed: bool = True
789
+ else:
790
+ model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
791
791
 
792
792
  def get_max_retries(self, max_retries: int) -> int:
793
793
  if isinstance(self.max_retries, NotGiven):
@@ -820,9 +820,9 @@ class FinalRequestOptions(pydantic.BaseModel):
820
820
  key: strip_not_given(value)
821
821
  for key, value in values.items()
822
822
  }
823
- if PYDANTIC_V2:
824
- return super().model_construct(_fields_set, **kwargs)
825
- return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
823
+ if PYDANTIC_V1:
824
+ return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
825
+ return super().model_construct(_fields_set, **kwargs)
826
826
 
827
827
  if not TYPE_CHECKING:
828
828
  # type checkers incorrectly complain about this assignment
@@ -10,7 +10,6 @@ from ._utils import (
10
10
  lru_cache as lru_cache,
11
11
  is_mapping as is_mapping,
12
12
  is_tuple_t as is_tuple_t,
13
- parse_date as parse_date,
14
13
  is_iterable as is_iterable,
15
14
  is_sequence as is_sequence,
16
15
  coerce_float as coerce_float,
@@ -23,7 +22,6 @@ from ._utils import (
23
22
  coerce_boolean as coerce_boolean,
24
23
  coerce_integer as coerce_integer,
25
24
  file_from_path as file_from_path,
26
- parse_datetime as parse_datetime,
27
25
  strip_not_given as strip_not_given,
28
26
  deepcopy_minimal as deepcopy_minimal,
29
27
  get_async_library as get_async_library,
@@ -32,6 +30,13 @@ from ._utils import (
32
30
  maybe_coerce_boolean as maybe_coerce_boolean,
33
31
  maybe_coerce_integer as maybe_coerce_integer,
34
32
  )
33
+ from ._compat import (
34
+ get_args as get_args,
35
+ is_union as is_union,
36
+ get_origin as get_origin,
37
+ is_typeddict as is_typeddict,
38
+ is_literal_type as is_literal_type,
39
+ )
35
40
  from ._typing import (
36
41
  is_list_type as is_list_type,
37
42
  is_union_type as is_union_type,
@@ -56,3 +61,4 @@ from ._reflection import (
56
61
  function_has_argument as function_has_argument,
57
62
  assert_signatures_in_sync as assert_signatures_in_sync,
58
63
  )
64
+ from ._datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ import typing_extensions
5
+ from typing import Any, Type, Union, Literal, Optional
6
+ from datetime import date, datetime
7
+ from typing_extensions import get_args as _get_args, get_origin as _get_origin
8
+
9
+ from .._types import StrBytesIntFloat
10
+ from ._datetime_parse import parse_date as _parse_date, parse_datetime as _parse_datetime
11
+
12
+ _LITERAL_TYPES = {Literal, typing_extensions.Literal}
13
+
14
+
15
+ def get_args(tp: type[Any]) -> tuple[Any, ...]:
16
+ return _get_args(tp)
17
+
18
+
19
+ def get_origin(tp: type[Any]) -> type[Any] | None:
20
+ return _get_origin(tp)
21
+
22
+
23
+ def is_union(tp: Optional[Type[Any]]) -> bool:
24
+ if sys.version_info < (3, 10):
25
+ return tp is Union # type: ignore[comparison-overlap]
26
+ else:
27
+ import types
28
+
29
+ return tp is Union or tp is types.UnionType
30
+
31
+
32
+ def is_typeddict(tp: Type[Any]) -> bool:
33
+ return typing_extensions.is_typeddict(tp)
34
+
35
+
36
+ def is_literal_type(tp: Type[Any]) -> bool:
37
+ return get_origin(tp) in _LITERAL_TYPES
38
+
39
+
40
+ def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
41
+ return _parse_date(value)
42
+
43
+
44
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
45
+ return _parse_datetime(value)
@@ -0,0 +1,136 @@
1
+ """
2
+ This file contains code from https://github.com/pydantic/pydantic/blob/main/pydantic/v1/datetime_parse.py
3
+ without the Pydantic v1 specific errors.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import re
9
+ from typing import Dict, Union, Optional
10
+ from datetime import date, datetime, timezone, timedelta
11
+
12
+ from .._types import StrBytesIntFloat
13
+
14
+ date_expr = r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
15
+ time_expr = (
16
+ r"(?P<hour>\d{1,2}):(?P<minute>\d{1,2})"
17
+ r"(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?"
18
+ r"(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$"
19
+ )
20
+
21
+ date_re = re.compile(f"{date_expr}$")
22
+ datetime_re = re.compile(f"{date_expr}[T ]{time_expr}")
23
+
24
+
25
+ EPOCH = datetime(1970, 1, 1)
26
+ # if greater than this, the number is in ms, if less than or equal it's in seconds
27
+ # (in seconds this is 11th October 2603, in ms it's 20th August 1970)
28
+ MS_WATERSHED = int(2e10)
29
+ # slightly more than datetime.max in ns - (datetime.max - EPOCH).total_seconds() * 1e9
30
+ MAX_NUMBER = int(3e20)
31
+
32
+
33
+ def _get_numeric(value: StrBytesIntFloat, native_expected_type: str) -> Union[None, int, float]:
34
+ if isinstance(value, (int, float)):
35
+ return value
36
+ try:
37
+ return float(value)
38
+ except ValueError:
39
+ return None
40
+ except TypeError:
41
+ raise TypeError(f"invalid type; expected {native_expected_type}, string, bytes, int or float") from None
42
+
43
+
44
+ def _from_unix_seconds(seconds: Union[int, float]) -> datetime:
45
+ if seconds > MAX_NUMBER:
46
+ return datetime.max
47
+ elif seconds < -MAX_NUMBER:
48
+ return datetime.min
49
+
50
+ while abs(seconds) > MS_WATERSHED:
51
+ seconds /= 1000
52
+ dt = EPOCH + timedelta(seconds=seconds)
53
+ return dt.replace(tzinfo=timezone.utc)
54
+
55
+
56
+ def _parse_timezone(value: Optional[str]) -> Union[None, int, timezone]:
57
+ if value == "Z":
58
+ return timezone.utc
59
+ elif value is not None:
60
+ offset_mins = int(value[-2:]) if len(value) > 3 else 0
61
+ offset = 60 * int(value[1:3]) + offset_mins
62
+ if value[0] == "-":
63
+ offset = -offset
64
+ return timezone(timedelta(minutes=offset))
65
+ else:
66
+ return None
67
+
68
+
69
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
70
+ """
71
+ Parse a datetime/int/float/string and return a datetime.datetime.
72
+
73
+ This function supports time zone offsets. When the input contains one,
74
+ the output uses a timezone with a fixed offset from UTC.
75
+
76
+ Raise ValueError if the input is well formatted but not a valid datetime.
77
+ Raise ValueError if the input isn't well formatted.
78
+ """
79
+ if isinstance(value, datetime):
80
+ return value
81
+
82
+ number = _get_numeric(value, "datetime")
83
+ if number is not None:
84
+ return _from_unix_seconds(number)
85
+
86
+ if isinstance(value, bytes):
87
+ value = value.decode()
88
+
89
+ assert not isinstance(value, (float, int))
90
+
91
+ match = datetime_re.match(value)
92
+ if match is None:
93
+ raise ValueError("invalid datetime format")
94
+
95
+ kw = match.groupdict()
96
+ if kw["microsecond"]:
97
+ kw["microsecond"] = kw["microsecond"].ljust(6, "0")
98
+
99
+ tzinfo = _parse_timezone(kw.pop("tzinfo"))
100
+ kw_: Dict[str, Union[None, int, timezone]] = {k: int(v) for k, v in kw.items() if v is not None}
101
+ kw_["tzinfo"] = tzinfo
102
+
103
+ return datetime(**kw_) # type: ignore
104
+
105
+
106
+ def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
107
+ """
108
+ Parse a date/int/float/string and return a datetime.date.
109
+
110
+ Raise ValueError if the input is well formatted but not a valid date.
111
+ Raise ValueError if the input isn't well formatted.
112
+ """
113
+ if isinstance(value, date):
114
+ if isinstance(value, datetime):
115
+ return value.date()
116
+ else:
117
+ return value
118
+
119
+ number = _get_numeric(value, "date")
120
+ if number is not None:
121
+ return _from_unix_seconds(number).date()
122
+
123
+ if isinstance(value, bytes):
124
+ value = value.decode()
125
+
126
+ assert not isinstance(value, (float, int))
127
+ match = date_re.match(value)
128
+ if match is None:
129
+ raise ValueError("invalid date format")
130
+
131
+ kw = {k: int(v) for k, v in match.groupdict().items()}
132
+
133
+ try:
134
+ return date(**kw)
135
+ except ValueError:
136
+ raise ValueError("invalid date format") from None