modal 1.0.5.dev27__py3-none-any.whl → 1.0.5.dev29__py3-none-any.whl

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.
modal/_serialization.py CHANGED
@@ -6,6 +6,8 @@ import typing
6
6
  from inspect import Parameter
7
7
  from typing import Any
8
8
 
9
+ import google.protobuf.message
10
+
9
11
  from modal._utils.async_utils import synchronizer
10
12
  from modal_proto import api_pb2
11
13
 
@@ -470,10 +472,31 @@ def deserialize_params(serialized_params: bytes, function_def: api_pb2.Function,
470
472
  api_pb2.ClassParameterInfo.PARAM_SERIALIZATION_FORMAT_PICKLE,
471
473
  ):
472
474
  # legacy serialization format - pickle of `(args, kwargs)` w/ support for modal object arguments
473
- param_args, param_kwargs = deserialize(serialized_params, _client)
475
+ try:
476
+ param_args, param_kwargs = deserialize(serialized_params, _client)
477
+ except DeserializationError as original_exc:
478
+ # Fallback in case of proto -> pickle downgrades of a parameter serialization format
479
+ # I.e. FunctionBindParams binding proto serialized params to a function defintion
480
+ # that now assumes pickled data according to class_parameter_info
481
+ param_args = ()
482
+ try:
483
+ param_kwargs = deserialize_proto_params(serialized_params)
484
+ except Exception:
485
+ raise original_exc
486
+
474
487
  elif function_def.class_parameter_info.format == api_pb2.ClassParameterInfo.PARAM_SERIALIZATION_FORMAT_PROTO:
475
488
  param_args = () # we use kwargs only for our implicit constructors
476
- param_kwargs = deserialize_proto_params(serialized_params)
489
+ try:
490
+ param_kwargs = deserialize_proto_params(serialized_params)
491
+ except google.protobuf.message.DecodeError as original_exc:
492
+ # Fallback in case of pickle -> proto upgrades of a parameter serialization format
493
+ # I.e. FunctionBindParams binding pickle serialized params to a function defintion
494
+ # that now assumes proto data according to class_parameter_info
495
+ try:
496
+ param_args, param_kwargs = deserialize(serialized_params, _client)
497
+ except Exception:
498
+ raise original_exc
499
+
477
500
  else:
478
501
  raise ExecutionError(
479
502
  f"Unknown class parameter serialization format: {function_def.class_parameter_info.format}"
modal/client.pyi CHANGED
@@ -31,7 +31,7 @@ class _Client:
31
31
  server_url: str,
32
32
  client_type: int,
33
33
  credentials: typing.Optional[tuple[str, str]],
34
- version: str = "1.0.5.dev27",
34
+ version: str = "1.0.5.dev29",
35
35
  ):
36
36
  """mdmd:hidden
37
37
  The Modal client object is not intended to be instantiated directly by users.
@@ -160,7 +160,7 @@ class Client:
160
160
  server_url: str,
161
161
  client_type: int,
162
162
  credentials: typing.Optional[tuple[str, str]],
163
- version: str = "1.0.5.dev27",
163
+ version: str = "1.0.5.dev29",
164
164
  ):
165
165
  """mdmd:hidden
166
166
  The Modal client object is not intended to be instantiated directly by users.
modal/parallel_map.py CHANGED
@@ -1,6 +1,7 @@
1
1
  # Copyright Modal Labs 2024
2
2
  import asyncio
3
3
  import enum
4
+ import inspect
4
5
  import time
5
6
  import typing
6
7
  from asyncio import FIRST_COMPLETED
@@ -27,6 +28,7 @@ from modal._utils.async_utils import (
27
28
  warn_if_generator_is_not_consumed,
28
29
  )
29
30
  from modal._utils.blob_utils import BLOB_MAX_PARALLELISM
31
+ from modal._utils.deprecation import deprecation_warning
30
32
  from modal._utils.function_utils import (
31
33
  ATTEMPT_TIMEOUT_GRACE_PERIOD,
32
34
  OUTPUTS_TIMEOUT,
@@ -409,7 +411,7 @@ async def _map_invocation(
409
411
  async_merge(drain_input_generator(), pump_inputs(), poll_outputs(), retry_inputs())
410
412
  ) as streamer:
411
413
  async for response in streamer:
412
- if response is not None:
414
+ if response is not None: # type: ignore[unreachable]
413
415
  yield response.value
414
416
  log_debug_stats_task.cancel()
415
417
  await log_debug_stats_task
@@ -434,7 +436,6 @@ async def _map_helper(
434
436
  We could make this explicit as an improvement or even let users decide what they
435
437
  prefer: throughput (prioritize queueing inputs) or latency (prioritize yielding results)
436
438
  """
437
-
438
439
  raw_input_queue: Any = SynchronizedQueue() # type: ignore
439
440
  await raw_input_queue.init.aio()
440
441
 
@@ -460,6 +461,33 @@ async def _map_helper(
460
461
  yield output
461
462
 
462
463
 
464
+ def _maybe_warn_about_exceptions(func_name: str, return_exceptions: bool, wrap_returned_exceptions: bool):
465
+ if return_exceptions and wrap_returned_exceptions:
466
+ deprecation_warning(
467
+ (2025, 6, 27),
468
+ (
469
+ f"Function.{func_name} currently leaks an internal exception wrapping type "
470
+ "(modal.exceptions.UserCodeException) when `return_exceptions=True` is set. "
471
+ "In the future, this will change, and the underlying exception will be returned directly.\n"
472
+ "To opt into the future behavior and silence this warning, add `wrap_returned_exceptions=False`:\n\n"
473
+ f" f.{func_name}(..., return_exceptions=True, wrap_returned_exceptions=False)"
474
+ ),
475
+ )
476
+
477
+
478
+ def _invoked_from_sync_wrapper() -> bool:
479
+ """Check whether the calling function was called from a sync wrapper."""
480
+ # This is temporary: we only need it to avoind double-firing the wrap_returned_exceptions warning.
481
+ # (We don't want to push the warning lower in the stack beacuse then we can't attribute to the user's code.)
482
+ try:
483
+ frame = inspect.currentframe()
484
+ caller_function_name = frame.f_back.f_back.f_code.co_name
485
+ # Embeds some assumptions about how the current calling stack works, but this is just temporary.
486
+ return caller_function_name == "asend"
487
+ except Exception:
488
+ return False
489
+
490
+
463
491
  @warn_if_generator_is_not_consumed(function_name="Function.map.aio")
464
492
  async def _map_async(
465
493
  self: "modal.functions.Function",
@@ -471,6 +499,8 @@ async def _map_async(
471
499
  return_exceptions: bool = False, # propagate exceptions (False) or aggregate them in the results list (True)
472
500
  wrap_returned_exceptions: bool = True, # wrap returned exceptions in modal.exception.UserCodeException
473
501
  ) -> typing.AsyncGenerator[Any, None]:
502
+ if not _invoked_from_sync_wrapper():
503
+ _maybe_warn_about_exceptions("map.aio", return_exceptions, wrap_returned_exceptions)
474
504
  async_input_gen = async_zip(*[sync_or_async_iter(it) for it in input_iterators])
475
505
  async for output in _map_helper(
476
506
  self,
@@ -493,6 +523,8 @@ async def _starmap_async(
493
523
  return_exceptions: bool = False,
494
524
  wrap_returned_exceptions: bool = True,
495
525
  ) -> typing.AsyncIterable[Any]:
526
+ if not _invoked_from_sync_wrapper():
527
+ _maybe_warn_about_exceptions("starmap.aio", return_exceptions, wrap_returned_exceptions)
496
528
  async for output in _map_helper(
497
529
  self,
498
530
  sync_or_async_iter(input_iterator),
@@ -509,7 +541,12 @@ async def _for_each_async(self, *input_iterators, kwargs={}, ignore_exceptions:
509
541
  # rather than iterating over the result
510
542
  async_input_gen = async_zip(*[sync_or_async_iter(it) for it in input_iterators])
511
543
  async for _ in _map_helper(
512
- self, async_input_gen, kwargs=kwargs, order_outputs=False, return_exceptions=ignore_exceptions
544
+ self,
545
+ async_input_gen,
546
+ kwargs=kwargs,
547
+ order_outputs=False,
548
+ return_exceptions=ignore_exceptions,
549
+ wrap_returned_exceptions=False,
513
550
  ):
514
551
  pass
515
552
 
@@ -559,6 +596,7 @@ def _map_sync(
559
596
  print(list(my_func.map(range(3), return_exceptions=True)))
560
597
  ```
561
598
  """
599
+ _maybe_warn_about_exceptions("map", return_exceptions, wrap_returned_exceptions)
562
600
 
563
601
  return AsyncOrSyncIterable(
564
602
  _map_async(
@@ -665,6 +703,7 @@ def _starmap_sync(
665
703
  assert list(my_func.starmap([(1, 2), (3, 4)])) == [3, 7]
666
704
  ```
667
705
  """
706
+ _maybe_warn_about_exceptions("starmap", return_exceptions, wrap_returned_exceptions)
668
707
  return AsyncOrSyncIterable(
669
708
  _starmap_async(
670
709
  self,
modal/parallel_map.pyi CHANGED
@@ -91,6 +91,11 @@ def _map_helper(
91
91
  """
92
92
  ...
93
93
 
94
+ def _maybe_warn_about_exceptions(func_name: str, return_exceptions: bool, wrap_returned_exceptions: bool): ...
95
+ def _invoked_from_sync_wrapper() -> bool:
96
+ """Check whether the calling function was called from a sync wrapper."""
97
+ ...
98
+
94
99
  def _map_async(
95
100
  self: modal.functions.Function,
96
101
  *input_iterators: typing.Union[typing.Iterable[typing.Any], typing.AsyncIterable[typing.Any]],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modal
3
- Version: 1.0.5.dev27
3
+ Version: 1.0.5.dev29
4
4
  Summary: Python client library for Modal
5
5
  Author-email: Modal Labs <support@modal.com>
6
6
  License: Apache-2.0
@@ -12,7 +12,7 @@ modal/_partial_function.py,sha256=RqBRBqezecNDK_Ve_X00Oaw5Loub7OaknfoWb7dcgSg,39
12
12
  modal/_pty.py,sha256=JZfPDDpzqICZqtyPI_oMJf_9w-p_lLNuzHhwhodUXio,1329
13
13
  modal/_resolver.py,sha256=-nolqj_p_mx5czVYj1Mazh2IQWpSMrTOGughVJqYfo8,7579
14
14
  modal/_resources.py,sha256=NMAp0GCLutiZI4GuKSIVnRHVlstoD3hNGUabjTUtzf4,1794
15
- modal/_serialization.py,sha256=iiD1SnSyEYRmZiVCaaWKJC87CamV-rqnyqs91XUjqoo,22971
15
+ modal/_serialization.py,sha256=MiUWk1yYhW2eKEsnD1_RsyDAsPsK0F00AgZONMqsWVA,24045
16
16
  modal/_traceback.py,sha256=IZQzB3fVlUfMHOSyKUgw0H6qv4yHnpyq-XVCNZKfUdA,5023
17
17
  modal/_tunnel.py,sha256=zTBxBiuH1O22tS1OliAJdIsSmaZS8PlnifS_6S5z-mk,6320
18
18
  modal/_tunnel.pyi,sha256=rvC7USR2BcKkbZIeCJXwf7-UfGE-LPLjKsGNiK7Lxa4,13366
@@ -22,7 +22,7 @@ modal/app.py,sha256=fCKq3TJ2Y5LB2WKNs6pp_5XECNH5avUL01jQljuoYRU,46603
22
22
  modal/app.pyi,sha256=Z6wi_dkXywiaM2rvAvguj2Wgu9ZgPjMSLl1nH1a7EYI,42243
23
23
  modal/call_graph.py,sha256=1g2DGcMIJvRy-xKicuf63IVE98gJSnQsr8R_NVMptNc,2581
24
24
  modal/client.py,sha256=OwISJvkgMb-rHm9Gc4i-7YcDgGiZgwJ7F_PzwZH7a6Q,16847
25
- modal/client.pyi,sha256=2UPMX_K24wJC68jJRKXPH0-m_LnuVVD6_Shs1gBQy7o,15081
25
+ modal/client.pyi,sha256=5l963mRZNjMD84Wk7bywoMoM8mdOqG2RpeWrF619paY,15081
26
26
  modal/cloud_bucket_mount.py,sha256=YOe9nnvSr4ZbeCn587d7_VhE9IioZYRvF9VYQTQux08,5914
27
27
  modal/cloud_bucket_mount.pyi,sha256=-qSfYAQvIoO_l2wsCCGTG5ZUwQieNKXdAO00yP1-LYU,7394
28
28
  modal/cls.py,sha256=s5UhFqNQz34aYOpmMTnlgQMhI7GfN3IkCLNlGXrrW7M,39795
@@ -52,8 +52,8 @@ modal/network_file_system.pyi,sha256=xKVVLn9s7qf8iSnDvPZhXeQx83nKynhiwzvMbYY-S_A
52
52
  modal/object.py,sha256=bTeskuY8JFrESjU4_UL_nTwYlBQdOLmVaOX3X6EMxsg,164
53
53
  modal/object.pyi,sha256=OT5nnTwPfQx1Uk0GkTQuGXBhznRk1yXGloH4VkTpcPg,6502
54
54
  modal/output.py,sha256=q4T9uHduunj4NwY-YSwkHGgjZlCXMuJbfQ5UFaAGRAc,1968
55
- modal/parallel_map.py,sha256=CnjC0-So6gGZtknuWZ_88MrprEbV2Xxb5TjVKlMmOes,38729
56
- modal/parallel_map.pyi,sha256=a1LDzsWGEERXl6uVKQ9KPxvgNkxqDnBWS8dkgZE2lJs,10051
55
+ modal/parallel_map.py,sha256=uRCIId1C1lHHprG3A5WdWkOBcl2DmlPTAxZAkXUrrow,40765
56
+ modal/parallel_map.pyi,sha256=-t3nZ-SvKEK8_xC4A_AmAq6UVpt4ZFtq7rPnWzHGhfg,10290
57
57
  modal/partial_function.py,sha256=SwuAAj2wj4SO6F6nkSnwNZrczEmm9w9YdlQTHh6hr04,1195
58
58
  modal/partial_function.pyi,sha256=-rhLIgXtLpP5weJw7U4aMcDxtFMwXJ1wf-nncPowUMg,14991
59
59
  modal/proxy.py,sha256=NQJJMGo-D2IfmeU0vb10WWaE4oTLcuf9jTeEJvactOg,1446
@@ -147,7 +147,7 @@ modal/requirements/2024.10.txt,sha256=qD-5cVIVM9wXesJ6JC89Ew-3m2KjEElUz3jaw_MddR
147
147
  modal/requirements/PREVIEW.txt,sha256=KxDaVTOwatHvboDo4lorlgJ7-n-MfAwbPwxJ0zcJqrs,312
148
148
  modal/requirements/README.md,sha256=9tK76KP0Uph7O0M5oUgsSwEZDj5y-dcUPsnpR0Sc-Ik,854
149
149
  modal/requirements/base-images.json,sha256=f1bwyp2UkM844eoO9Qk30gQw_xrMqKpMSeJ6MErXnEk,995
150
- modal-1.0.5.dev27.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
150
+ modal-1.0.5.dev29.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
151
151
  modal_docs/__init__.py,sha256=svYKtV8HDwDCN86zbdWqyq5T8sMdGDj0PVlzc2tIxDM,28
152
152
  modal_docs/gen_cli_docs.py,sha256=c1yfBS_x--gL5bs0N4ihMwqwX8l3IBWSkBAKNNIi6bQ,3801
153
153
  modal_docs/gen_reference_docs.py,sha256=d_CQUGQ0rfw28u75I2mov9AlS773z9rG40-yq5o7g2U,6359
@@ -170,10 +170,10 @@ modal_proto/options_pb2.pyi,sha256=l7DBrbLO7q3Ir-XDkWsajm0d0TQqqrfuX54i4BMpdQg,1
170
170
  modal_proto/options_pb2_grpc.py,sha256=1oboBPFxaTEXt9Aw7EAj8gXHDCNMhZD2VXqocC9l_gk,159
171
171
  modal_proto/options_pb2_grpc.pyi,sha256=CImmhxHsYnF09iENPoe8S4J-n93jtgUYD2JPAc0yJSI,247
172
172
  modal_proto/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
173
- modal_version/__init__.py,sha256=s50C7NrfUbhzAEmHtBAyUXTDNJhYwpnksN-tHp1c5EU,121
173
+ modal_version/__init__.py,sha256=yv5QOKhz4AEyouhTzuSKxdOGjAnvYzyQZ6k45PKQHZA,121
174
174
  modal_version/__main__.py,sha256=2FO0yYQQwDTh6udt1h-cBnGd1c4ZyHnHSI4BksxzVac,105
175
- modal-1.0.5.dev27.dist-info/METADATA,sha256=xbxHebDVNDkZJI7egQ7vbkouxfdEZE5RT4Bg5Y_Av60,2462
176
- modal-1.0.5.dev27.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
177
- modal-1.0.5.dev27.dist-info/entry_points.txt,sha256=An-wYgeEUnm6xzrAP9_NTSTSciYvvEWsMZILtYrvpAI,46
178
- modal-1.0.5.dev27.dist-info/top_level.txt,sha256=4BWzoKYREKUZ5iyPzZpjqx4G8uB5TWxXPDwibLcVa7k,43
179
- modal-1.0.5.dev27.dist-info/RECORD,,
175
+ modal-1.0.5.dev29.dist-info/METADATA,sha256=7keYFc69yH-enj0TrIG4pgn6urEKFWH5wL_GWa0TkQ0,2462
176
+ modal-1.0.5.dev29.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
177
+ modal-1.0.5.dev29.dist-info/entry_points.txt,sha256=An-wYgeEUnm6xzrAP9_NTSTSciYvvEWsMZILtYrvpAI,46
178
+ modal-1.0.5.dev29.dist-info/top_level.txt,sha256=4BWzoKYREKUZ5iyPzZpjqx4G8uB5TWxXPDwibLcVa7k,43
179
+ modal-1.0.5.dev29.dist-info/RECORD,,
modal_version/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # Copyright Modal Labs 2025
2
2
  """Supplies the current version of the modal client library."""
3
3
 
4
- __version__ = "1.0.5.dev27"
4
+ __version__ = "1.0.5.dev29"