runwayml 2.1.0__tar.gz → 2.1.2__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 (71) hide show
  1. runwayml-2.1.2/.release-please-manifest.json +3 -0
  2. {runwayml-2.1.0 → runwayml-2.1.2}/CHANGELOG.md +31 -0
  3. {runwayml-2.1.0 → runwayml-2.1.2}/PKG-INFO +8 -10
  4. {runwayml-2.1.0 → runwayml-2.1.2}/README.md +6 -6
  5. {runwayml-2.1.0 → runwayml-2.1.2}/mypy.ini +4 -1
  6. {runwayml-2.1.0 → runwayml-2.1.2}/pyproject.toml +2 -2
  7. {runwayml-2.1.0 → runwayml-2.1.2}/requirements-dev.lock +3 -1
  8. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_base_client.py +8 -4
  9. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_compat.py +3 -5
  10. runwayml-2.1.2/src/runwayml/_utils/_sync.py +71 -0
  11. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_transform.py +5 -0
  12. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_version.py +1 -1
  13. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_client.py +38 -0
  14. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_models.py +8 -0
  15. runwayml-2.1.0/.release-please-manifest.json +0 -3
  16. runwayml-2.1.0/src/runwayml/_utils/_sync.py +0 -81
  17. {runwayml-2.1.0 → runwayml-2.1.2}/.gitignore +0 -0
  18. {runwayml-2.1.0 → runwayml-2.1.2}/CONTRIBUTING.md +0 -0
  19. {runwayml-2.1.0 → runwayml-2.1.2}/LICENSE +0 -0
  20. {runwayml-2.1.0 → runwayml-2.1.2}/SECURITY.md +0 -0
  21. {runwayml-2.1.0 → runwayml-2.1.2}/api.md +0 -0
  22. {runwayml-2.1.0 → runwayml-2.1.2}/bin/check-release-environment +0 -0
  23. {runwayml-2.1.0 → runwayml-2.1.2}/bin/publish-pypi +0 -0
  24. {runwayml-2.1.0 → runwayml-2.1.2}/examples/.keep +0 -0
  25. {runwayml-2.1.0 → runwayml-2.1.2}/noxfile.py +0 -0
  26. {runwayml-2.1.0 → runwayml-2.1.2}/release-please-config.json +0 -0
  27. {runwayml-2.1.0 → runwayml-2.1.2}/requirements.lock +0 -0
  28. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/__init__.py +0 -0
  29. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_client.py +0 -0
  30. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_constants.py +0 -0
  31. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_exceptions.py +0 -0
  32. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_files.py +0 -0
  33. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_models.py +0 -0
  34. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_qs.py +0 -0
  35. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_resource.py +0 -0
  36. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_response.py +0 -0
  37. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_streaming.py +0 -0
  38. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_types.py +0 -0
  39. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/__init__.py +0 -0
  40. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_logs.py +0 -0
  41. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_proxy.py +0 -0
  42. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_reflection.py +0 -0
  43. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_streams.py +0 -0
  44. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_typing.py +0 -0
  45. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/_utils/_utils.py +0 -0
  46. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/lib/.keep +0 -0
  47. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/py.typed +0 -0
  48. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/resources/__init__.py +0 -0
  49. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/resources/image_to_video.py +0 -0
  50. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/resources/tasks.py +0 -0
  51. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/types/__init__.py +0 -0
  52. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/types/image_to_video_create_params.py +0 -0
  53. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/types/image_to_video_create_response.py +0 -0
  54. {runwayml-2.1.0 → runwayml-2.1.2}/src/runwayml/types/task_retrieve_response.py +0 -0
  55. {runwayml-2.1.0 → runwayml-2.1.2}/tests/__init__.py +0 -0
  56. {runwayml-2.1.0 → runwayml-2.1.2}/tests/api_resources/__init__.py +0 -0
  57. {runwayml-2.1.0 → runwayml-2.1.2}/tests/api_resources/test_image_to_video.py +0 -0
  58. {runwayml-2.1.0 → runwayml-2.1.2}/tests/api_resources/test_tasks.py +0 -0
  59. {runwayml-2.1.0 → runwayml-2.1.2}/tests/conftest.py +0 -0
  60. {runwayml-2.1.0 → runwayml-2.1.2}/tests/sample_file.txt +0 -0
  61. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_deepcopy.py +0 -0
  62. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_extract_files.py +0 -0
  63. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_files.py +0 -0
  64. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_qs.py +0 -0
  65. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_required_args.py +0 -0
  66. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_response.py +0 -0
  67. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_streaming.py +0 -0
  68. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_transform.py +0 -0
  69. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_utils/test_proxy.py +0 -0
  70. {runwayml-2.1.0 → runwayml-2.1.2}/tests/test_utils/test_typing.py +0 -0
  71. {runwayml-2.1.0 → runwayml-2.1.2}/tests/utils.py +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "2.1.2"
3
+ }
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.2 (2024-12-03)
4
+
5
+ Full Changelog: [v2.1.1...v2.1.2](https://github.com/runwayml/sdk-python/compare/v2.1.1...v2.1.2)
6
+
7
+ ### Chores
8
+
9
+ * **internal:** bump pyright ([#32](https://github.com/runwayml/sdk-python/issues/32)) ([7d36972](https://github.com/runwayml/sdk-python/commit/7d36972a3afa9335141b848cb9783c649a4933ae))
10
+
11
+ ## 2.1.1 (2024-11-28)
12
+
13
+ Full Changelog: [v2.1.0...v2.1.1](https://github.com/runwayml/sdk-python/compare/v2.1.0...v2.1.1)
14
+
15
+ ### Bug Fixes
16
+
17
+ * **client:** compat with new httpx 0.28.0 release ([#28](https://github.com/runwayml/sdk-python/issues/28)) ([f5e637e](https://github.com/runwayml/sdk-python/commit/f5e637eb373bc6fa85ca6d123bbdaaa1161bc814))
18
+
19
+
20
+ ### Chores
21
+
22
+ * **internal:** exclude mypy from running on tests ([#27](https://github.com/runwayml/sdk-python/issues/27)) ([d724387](https://github.com/runwayml/sdk-python/commit/d724387c6546ba476e2773f2249475285dca32c9))
23
+ * **internal:** fix compat model_dump method when warnings are passed ([#24](https://github.com/runwayml/sdk-python/issues/24)) ([61c8490](https://github.com/runwayml/sdk-python/commit/61c849057b971f8b19846ed08b5145c4321adf04))
24
+ * rebuild project due to codegen change ([#19](https://github.com/runwayml/sdk-python/issues/19)) ([2a4cf56](https://github.com/runwayml/sdk-python/commit/2a4cf56335868d88e07aac767260c0c7509b1c94))
25
+ * rebuild project due to codegen change ([#21](https://github.com/runwayml/sdk-python/issues/21)) ([e680d5b](https://github.com/runwayml/sdk-python/commit/e680d5b5bf3ee7fcdede74c7d5c5a971ea18675e))
26
+ * rebuild project due to codegen change ([#22](https://github.com/runwayml/sdk-python/issues/22)) ([ecddf51](https://github.com/runwayml/sdk-python/commit/ecddf51a41704e42f2612541d3841990f22f7220))
27
+ * remove now unused `cached-property` dep ([#26](https://github.com/runwayml/sdk-python/issues/26)) ([21e64d0](https://github.com/runwayml/sdk-python/commit/21e64d0603003c58918dde0b5b6e94b7df28707c))
28
+
29
+
30
+ ### Documentation
31
+
32
+ * add info log level to readme ([#25](https://github.com/runwayml/sdk-python/issues/25)) ([d6e4ed4](https://github.com/runwayml/sdk-python/commit/d6e4ed45841a88e13c30dd318706a18bf86a8550))
33
+
3
34
  ## 2.1.0 (2024-11-06)
4
35
 
5
36
  Full Changelog: [v2.0.0...v2.1.0](https://github.com/runwayml/sdk-python/compare/v2.0.0...v2.1.0)
@@ -1,12 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: runwayml
3
- Version: 2.1.0
3
+ Version: 2.1.2
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
7
7
  Author-email: RunwayML <dev-feedback@runwayml.com>
8
- License-Expression: Apache-2.0
9
- License-File: LICENSE
8
+ License: Apache-2.0
10
9
  Classifier: Intended Audience :: Developers
11
10
  Classifier: License :: OSI Approved :: Apache Software License
12
11
  Classifier: Operating System :: MacOS
@@ -23,7 +22,6 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
22
  Classifier: Typing :: Typed
24
23
  Requires-Python: >=3.8
25
24
  Requires-Dist: anyio<5,>=3.5.0
26
- Requires-Dist: cached-property; python_version < '3.8'
27
25
  Requires-Dist: distro<2,>=1.7.0
28
26
  Requires-Dist: httpx<1,>=0.23.0
29
27
  Requires-Dist: pydantic<3,>=1.9.0
@@ -61,8 +59,7 @@ import os
61
59
  from runwayml import RunwayML
62
60
 
63
61
  client = RunwayML(
64
- # This is the default and can be omitted
65
- api_key=os.environ.get("RUNWAYML_API_SECRET"),
62
+ api_key=os.environ.get("RUNWAYML_API_SECRET"), # This is the default and can be omitted
66
63
  )
67
64
 
68
65
  image_to_video = client.image_to_video.create(
@@ -88,8 +85,7 @@ import asyncio
88
85
  from runwayml import AsyncRunwayML
89
86
 
90
87
  client = AsyncRunwayML(
91
- # This is the default and can be omitted
92
- api_key=os.environ.get("RUNWAYML_API_SECRET"),
88
+ api_key=os.environ.get("RUNWAYML_API_SECRET"), # This is the default and can be omitted
93
89
  )
94
90
 
95
91
 
@@ -223,12 +219,14 @@ Note that requests that time out are [retried twice by default](https://github.c
223
219
 
224
220
  We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
225
221
 
226
- You can enable logging by setting the environment variable `RUNWAYML_LOG` to `debug`.
222
+ You can enable logging by setting the environment variable `RUNWAYML_LOG` to `info`.
227
223
 
228
224
  ```shell
229
- $ export RUNWAYML_LOG=debug
225
+ $ export RUNWAYML_LOG=info
230
226
  ```
231
227
 
228
+ Or to `debug` for more verbose logging.
229
+
232
230
  ### How to tell whether `None` means `null` or missing
233
231
 
234
232
  In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
@@ -28,8 +28,7 @@ import os
28
28
  from runwayml import RunwayML
29
29
 
30
30
  client = RunwayML(
31
- # This is the default and can be omitted
32
- api_key=os.environ.get("RUNWAYML_API_SECRET"),
31
+ api_key=os.environ.get("RUNWAYML_API_SECRET"), # This is the default and can be omitted
33
32
  )
34
33
 
35
34
  image_to_video = client.image_to_video.create(
@@ -55,8 +54,7 @@ import asyncio
55
54
  from runwayml import AsyncRunwayML
56
55
 
57
56
  client = AsyncRunwayML(
58
- # This is the default and can be omitted
59
- api_key=os.environ.get("RUNWAYML_API_SECRET"),
57
+ api_key=os.environ.get("RUNWAYML_API_SECRET"), # This is the default and can be omitted
60
58
  )
61
59
 
62
60
 
@@ -190,12 +188,14 @@ Note that requests that time out are [retried twice by default](#retries).
190
188
 
191
189
  We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
192
190
 
193
- You can enable logging by setting the environment variable `RUNWAYML_LOG` to `debug`.
191
+ You can enable logging by setting the environment variable `RUNWAYML_LOG` to `info`.
194
192
 
195
193
  ```shell
196
- $ export RUNWAYML_LOG=debug
194
+ $ export RUNWAYML_LOG=info
197
195
  ```
198
196
 
197
+ Or to `debug` for more verbose logging.
198
+
199
199
  ### How to tell whether `None` means `null` or missing
200
200
 
201
201
  In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
@@ -5,7 +5,10 @@ show_error_codes = True
5
5
  # Exclude _files.py because mypy isn't smart enough to apply
6
6
  # the correct type narrowing and as this is an internal module
7
7
  # it's fine to just use Pyright.
8
- exclude = ^(src/runwayml/_files\.py|_dev/.*\.py)$
8
+ #
9
+ # We also exclude our `tests` as mypy doesn't always infer
10
+ # types correctly and Pyright will still catch any type errors.
11
+ exclude = ^(src/runwayml/_files\.py|_dev/.*\.py|tests/.*)$
9
12
 
10
13
  strict_equality = True
11
14
  implicit_reexport = True
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "runwayml"
3
- version = "2.1.0"
3
+ version = "2.1.2"
4
4
  description = "The official Python library for the runwayml API"
5
5
  dynamic = ["readme"]
6
6
  license = "Apache-2.0"
@@ -14,7 +14,6 @@ dependencies = [
14
14
  "anyio>=3.5.0, <5",
15
15
  "distro>=1.7.0, <2",
16
16
  "sniffio",
17
- "cached-property; python_version < '3.8'",
18
17
  ]
19
18
  requires-python = ">= 3.8"
20
19
  classifiers = [
@@ -55,6 +54,7 @@ dev-dependencies = [
55
54
  "dirty-equals>=0.6.0",
56
55
  "importlib-metadata>=6.7.0",
57
56
  "rich>=13.7.1",
57
+ "nest_asyncio==1.6.0"
58
58
  ]
59
59
 
60
60
  [tool.rye.scripts]
@@ -51,6 +51,7 @@ mdurl==0.1.2
51
51
  mypy==1.13.0
52
52
  mypy-extensions==1.0.0
53
53
  # via mypy
54
+ nest-asyncio==1.6.0
54
55
  nodeenv==1.8.0
55
56
  # via pyright
56
57
  nox==2023.4.22
@@ -67,7 +68,7 @@ pydantic-core==2.23.4
67
68
  # via pydantic
68
69
  pygments==2.18.0
69
70
  # via rich
70
- pyright==1.1.380
71
+ pyright==1.1.389
71
72
  pytest==8.3.3
72
73
  # via pytest-asyncio
73
74
  pytest-asyncio==0.24.0
@@ -95,6 +96,7 @@ typing-extensions==4.12.2
95
96
  # via mypy
96
97
  # via pydantic
97
98
  # via pydantic-core
99
+ # via pyright
98
100
  # via runwayml
99
101
  virtualenv==20.24.5
100
102
  # via nox
@@ -792,6 +792,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
792
792
  custom_query: Mapping[str, object] | None = None,
793
793
  _strict_response_validation: bool,
794
794
  ) -> None:
795
+ kwargs: dict[str, Any] = {}
795
796
  if limits is not None:
796
797
  warnings.warn(
797
798
  "The `connection_pool_limits` argument is deprecated. The `http_client` argument should be passed instead",
@@ -804,6 +805,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
804
805
  limits = DEFAULT_CONNECTION_LIMITS
805
806
 
806
807
  if transport is not None:
808
+ kwargs["transport"] = transport
807
809
  warnings.warn(
808
810
  "The `transport` argument is deprecated. The `http_client` argument should be passed instead",
809
811
  category=DeprecationWarning,
@@ -813,6 +815,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
813
815
  raise ValueError("The `http_client` argument is mutually exclusive with `transport`")
814
816
 
815
817
  if proxies is not None:
818
+ kwargs["proxies"] = proxies
816
819
  warnings.warn(
817
820
  "The `proxies` argument is deprecated. The `http_client` argument should be passed instead",
818
821
  category=DeprecationWarning,
@@ -856,10 +859,9 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
856
859
  base_url=base_url,
857
860
  # cast to a valid type because mypy doesn't understand our type narrowing
858
861
  timeout=cast(Timeout, timeout),
859
- proxies=proxies,
860
- transport=transport,
861
862
  limits=limits,
862
863
  follow_redirects=True,
864
+ **kwargs, # type: ignore
863
865
  )
864
866
 
865
867
  def is_closed(self) -> bool:
@@ -1358,6 +1360,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1358
1360
  custom_headers: Mapping[str, str] | None = None,
1359
1361
  custom_query: Mapping[str, object] | None = None,
1360
1362
  ) -> None:
1363
+ kwargs: dict[str, Any] = {}
1361
1364
  if limits is not None:
1362
1365
  warnings.warn(
1363
1366
  "The `connection_pool_limits` argument is deprecated. The `http_client` argument should be passed instead",
@@ -1370,6 +1373,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1370
1373
  limits = DEFAULT_CONNECTION_LIMITS
1371
1374
 
1372
1375
  if transport is not None:
1376
+ kwargs["transport"] = transport
1373
1377
  warnings.warn(
1374
1378
  "The `transport` argument is deprecated. The `http_client` argument should be passed instead",
1375
1379
  category=DeprecationWarning,
@@ -1379,6 +1383,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1379
1383
  raise ValueError("The `http_client` argument is mutually exclusive with `transport`")
1380
1384
 
1381
1385
  if proxies is not None:
1386
+ kwargs["proxies"] = proxies
1382
1387
  warnings.warn(
1383
1388
  "The `proxies` argument is deprecated. The `http_client` argument should be passed instead",
1384
1389
  category=DeprecationWarning,
@@ -1422,10 +1427,9 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1422
1427
  base_url=base_url,
1423
1428
  # cast to a valid type because mypy doesn't understand our type narrowing
1424
1429
  timeout=cast(Timeout, timeout),
1425
- proxies=proxies,
1426
- transport=transport,
1427
1430
  limits=limits,
1428
1431
  follow_redirects=True,
1432
+ **kwargs, # type: ignore
1429
1433
  )
1430
1434
 
1431
1435
  def is_closed(self) -> bool:
@@ -145,7 +145,8 @@ def model_dump(
145
145
  exclude=exclude,
146
146
  exclude_unset=exclude_unset,
147
147
  exclude_defaults=exclude_defaults,
148
- warnings=warnings,
148
+ # warnings are not supported in Pydantic v1
149
+ warnings=warnings if PYDANTIC_V2 else True,
149
150
  )
150
151
  return cast(
151
152
  "dict[str, Any]",
@@ -213,9 +214,6 @@ if TYPE_CHECKING:
213
214
  # __set__ is not defined at runtime, but @cached_property is designed to be settable
214
215
  def __set__(self, instance: object, value: _T) -> None: ...
215
216
  else:
216
- try:
217
- from functools import cached_property as cached_property
218
- except ImportError:
219
- from cached_property import cached_property as cached_property
217
+ from functools import cached_property as cached_property
220
218
 
221
219
  typed_cached_property = cached_property
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ import asyncio
5
+ import functools
6
+ import contextvars
7
+ from typing import Any, TypeVar, Callable, Awaitable
8
+ from typing_extensions import ParamSpec
9
+
10
+ T_Retval = TypeVar("T_Retval")
11
+ T_ParamSpec = ParamSpec("T_ParamSpec")
12
+
13
+
14
+ if sys.version_info >= (3, 9):
15
+ to_thread = asyncio.to_thread
16
+ else:
17
+ # backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
18
+ # for Python 3.8 support
19
+ async def to_thread(
20
+ func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
21
+ ) -> Any:
22
+ """Asynchronously run function *func* in a separate thread.
23
+
24
+ Any *args and **kwargs supplied for this function are directly passed
25
+ to *func*. Also, the current :class:`contextvars.Context` is propagated,
26
+ allowing context variables from the main thread to be accessed in the
27
+ separate thread.
28
+
29
+ Returns a coroutine that can be awaited to get the eventual result of *func*.
30
+ """
31
+ loop = asyncio.events.get_running_loop()
32
+ ctx = contextvars.copy_context()
33
+ func_call = functools.partial(ctx.run, func, *args, **kwargs)
34
+ return await loop.run_in_executor(None, func_call)
35
+
36
+
37
+ # inspired by `asyncer`, https://github.com/tiangolo/asyncer
38
+ def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
39
+ """
40
+ Take a blocking function and create an async one that receives the same
41
+ positional and keyword arguments. For python version 3.9 and above, it uses
42
+ asyncio.to_thread to run the function in a separate thread. For python version
43
+ 3.8, it uses locally defined copy of the asyncio.to_thread function which was
44
+ introduced in python 3.9.
45
+
46
+ Usage:
47
+
48
+ ```python
49
+ def blocking_func(arg1, arg2, kwarg1=None):
50
+ # blocking code
51
+ return result
52
+
53
+
54
+ result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)
55
+ ```
56
+
57
+ ## Arguments
58
+
59
+ `function`: a blocking regular callable (e.g. a function)
60
+
61
+ ## Return
62
+
63
+ An async function that takes the same positional and keyword arguments as the
64
+ original one, that when called runs the same original function in a thread worker
65
+ and returns the result.
66
+ """
67
+
68
+ async def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
69
+ return await to_thread(function, *args, **kwargs)
70
+
71
+ return wrapper
@@ -316,6 +316,11 @@ async def _async_transform_recursive(
316
316
  # Iterable[T]
317
317
  or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
318
318
  ):
319
+ # dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
320
+ # intended as an iterable, so we don't transform it.
321
+ if isinstance(data, dict):
322
+ return cast(object, data)
323
+
319
324
  inner_type = extract_type_arg(stripped_type, 0)
320
325
  return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
321
326
 
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "runwayml"
4
- __version__ = "2.1.0" # x-release-please-version
4
+ __version__ = "2.1.2" # x-release-please-version
@@ -4,11 +4,14 @@ from __future__ import annotations
4
4
 
5
5
  import gc
6
6
  import os
7
+ import sys
7
8
  import json
8
9
  import asyncio
9
10
  import inspect
11
+ import subprocess
10
12
  import tracemalloc
11
13
  from typing import Any, Union, cast
14
+ from textwrap import dedent
12
15
  from unittest import mock
13
16
  from typing_extensions import Literal
14
17
 
@@ -1630,3 +1633,38 @@ class TestAsyncRunwayML:
1630
1633
  )
1631
1634
 
1632
1635
  assert response.http_request.headers.get("x-stainless-retry-count") == "42"
1636
+
1637
+ def test_get_platform(self) -> None:
1638
+ # A previous implementation of asyncify could leave threads unterminated when
1639
+ # used with nest_asyncio.
1640
+ #
1641
+ # Since nest_asyncio.apply() is global and cannot be un-applied, this
1642
+ # test is run in a separate process to avoid affecting other tests.
1643
+ test_code = dedent("""
1644
+ import asyncio
1645
+ import nest_asyncio
1646
+ import threading
1647
+
1648
+ from runwayml._utils import asyncify
1649
+ from runwayml._base_client import get_platform
1650
+
1651
+ async def test_main() -> None:
1652
+ result = await asyncify(get_platform)()
1653
+ print(result)
1654
+ for thread in threading.enumerate():
1655
+ print(thread.name)
1656
+
1657
+ nest_asyncio.apply()
1658
+ asyncio.run(test_main())
1659
+ """)
1660
+ with subprocess.Popen(
1661
+ [sys.executable, "-c", test_code],
1662
+ text=True,
1663
+ ) as process:
1664
+ try:
1665
+ process.wait(2)
1666
+ if process.returncode:
1667
+ raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1668
+ except subprocess.TimeoutExpired as e:
1669
+ process.kill()
1670
+ raise AssertionError("calling get_platform using asyncify resulted in a hung process") from e
@@ -561,6 +561,14 @@ def test_forwards_compat_model_dump_method() -> None:
561
561
  m.model_dump(warnings=False)
562
562
 
563
563
 
564
+ def test_compat_method_no_error_for_warnings() -> None:
565
+ class Model(BaseModel):
566
+ foo: Optional[str]
567
+
568
+ m = Model(foo="hello")
569
+ assert isinstance(model_dump(m, warnings=False), dict)
570
+
571
+
564
572
  def test_to_json() -> None:
565
573
  class Model(BaseModel):
566
574
  foo: Optional[str] = Field(alias="FOO", default=None)
@@ -1,3 +0,0 @@
1
- {
2
- ".": "2.1.0"
3
- }
@@ -1,81 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import functools
4
- from typing import TypeVar, Callable, Awaitable
5
- from typing_extensions import ParamSpec
6
-
7
- import anyio
8
- import anyio.to_thread
9
-
10
- from ._reflection import function_has_argument
11
-
12
- T_Retval = TypeVar("T_Retval")
13
- T_ParamSpec = ParamSpec("T_ParamSpec")
14
-
15
-
16
- # copied from `asyncer`, https://github.com/tiangolo/asyncer
17
- def asyncify(
18
- function: Callable[T_ParamSpec, T_Retval],
19
- *,
20
- cancellable: bool = False,
21
- limiter: anyio.CapacityLimiter | None = None,
22
- ) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
23
- """
24
- Take a blocking function and create an async one that receives the same
25
- positional and keyword arguments, and that when called, calls the original function
26
- in a worker thread using `anyio.to_thread.run_sync()`. Internally,
27
- `asyncer.asyncify()` uses the same `anyio.to_thread.run_sync()`, but it supports
28
- keyword arguments additional to positional arguments and it adds better support for
29
- autocompletion and inline errors for the arguments of the function called and the
30
- return value.
31
-
32
- If the `cancellable` option is enabled and the task waiting for its completion is
33
- cancelled, the thread will still run its course but its return value (or any raised
34
- exception) will be ignored.
35
-
36
- Use it like this:
37
-
38
- ```Python
39
- def do_work(arg1, arg2, kwarg1="", kwarg2="") -> str:
40
- # Do work
41
- return "Some result"
42
-
43
-
44
- result = await to_thread.asyncify(do_work)("spam", "ham", kwarg1="a", kwarg2="b")
45
- print(result)
46
- ```
47
-
48
- ## Arguments
49
-
50
- `function`: a blocking regular callable (e.g. a function)
51
- `cancellable`: `True` to allow cancellation of the operation
52
- `limiter`: capacity limiter to use to limit the total amount of threads running
53
- (if omitted, the default limiter is used)
54
-
55
- ## Return
56
-
57
- An async function that takes the same positional and keyword arguments as the
58
- original one, that when called runs the same original function in a thread worker
59
- and returns the result.
60
- """
61
-
62
- async def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
63
- partial_f = functools.partial(function, *args, **kwargs)
64
-
65
- # In `v4.1.0` anyio added the `abandon_on_cancel` argument and deprecated the old
66
- # `cancellable` argument, so we need to use the new `abandon_on_cancel` to avoid
67
- # surfacing deprecation warnings.
68
- if function_has_argument(anyio.to_thread.run_sync, "abandon_on_cancel"):
69
- return await anyio.to_thread.run_sync(
70
- partial_f,
71
- abandon_on_cancel=cancellable,
72
- limiter=limiter,
73
- )
74
-
75
- return await anyio.to_thread.run_sync(
76
- partial_f,
77
- cancellable=cancellable,
78
- limiter=limiter,
79
- )
80
-
81
- return wrapper
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes