pyglove 0.5.0.dev202510160810__py3-none-any.whl → 0.5.0.dev202510170226__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.

Potentially problematic release.


This version of pyglove might be problematic. Click here for more details.

@@ -15,6 +15,7 @@
15
15
 
16
16
  import contextlib
17
17
  import dataclasses
18
+ import inspect
18
19
  import threading
19
20
  from typing import Any, Callable, ContextManager, Iterator, Optional
20
21
 
@@ -89,10 +90,14 @@ def with_contextual_override(func: Callable[..., Any]) -> Callable[..., Any]:
89
90
  with contextual_override() as current_context:
90
91
  pass
91
92
 
92
- def _func(*args, **kwargs) -> Any:
93
- with contextual_override(**current_context):
94
- return func(*args, **kwargs)
95
-
93
+ if inspect.iscoroutinefunction(func):
94
+ async def _func(*args, **kwargs) -> Any:
95
+ with contextual_override(**current_context):
96
+ return await func(*args, **kwargs)
97
+ else:
98
+ def _func(*args, **kwargs) -> Any:
99
+ with contextual_override(**current_context):
100
+ return func(*args, **kwargs)
96
101
  return _func
97
102
 
98
103
 
@@ -11,6 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
+ import asyncio
14
15
  import concurrent.futures
15
16
  import unittest
16
17
  from pyglove.core.utils import contextual
@@ -83,6 +84,15 @@ class ContextualTest(unittest.TestCase):
83
84
  [3]
84
85
  )
85
86
 
87
+ def test_with_contextual_override_async_func(self):
88
+ async def func(i):
89
+ del i
90
+ return contextual.contextual_value('x')
91
+
92
+ with contextual.contextual_override(x=3):
93
+ self.assertEqual(
94
+ asyncio.run(contextual.with_contextual_override(func)(0)), 3
95
+ )
86
96
 
87
97
  if __name__ == '__main__':
88
98
  unittest.main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyglove
3
- Version: 0.5.0.dev202510160810
3
+ Version: 0.5.0.dev202510170226
4
4
  Summary: PyGlove: A library for manipulating Python objects.
5
5
  Home-page: https://github.com/google/pyglove
6
6
  Author: PyGlove Authors
@@ -139,8 +139,8 @@ pyglove/core/typing/value_specs_test.py,sha256=eGXVxdduIM-oEaapJS9Kh7WSQHRUFegLI
139
139
  pyglove/core/utils/__init__.py,sha256=2aw4n1kYG9xlX2tWI-H5i25cBuK1ME9Lmf-F31VlKEk,8657
140
140
  pyglove/core/utils/common_traits.py,sha256=PWxOgPhG5H60ZwfO8xNAEGRjFUqqDZQBWQYomOfvdy8,3640
141
141
  pyglove/core/utils/common_traits_test.py,sha256=DIuZB_1xfmeTVfWnGOguDQcDAM_iGgBOe8C-5CsIqBc,1122
142
- pyglove/core/utils/contextual.py,sha256=RxBQkDM2gB6QwZj_2oMels6oh-zQPGJJlinZbbqHuYQ,5148
143
- pyglove/core/utils/contextual_test.py,sha256=OOcthquVyAekTqt1RyYcEMHaockMIokpbv4pSf13Nzs,3252
142
+ pyglove/core/utils/contextual.py,sha256=_EO_ubCcmI81QyYyyucm3QcH1asQWSeXvT2Xa4KONs8,5355
143
+ pyglove/core/utils/contextual_test.py,sha256=g5P6IBf6XgQTUW83QTDC1K5JQJ9bxP6ULiAj2ko4mMo,3552
144
144
  pyglove/core/utils/docstr_utils.py,sha256=5BY40kXozPKVGOB0eN8jy1P5_GHIzqFJ9FXAu_kzxaw,5119
145
145
  pyglove/core/utils/docstr_utils_test.py,sha256=TBHNwvhGyyoEs7dNOv5bW7h3B_y2smDyoAR9uPDiidI,4179
146
146
  pyglove/core/utils/error_utils.py,sha256=5if1LlouHMx9EkZt-rhlkDU53Qc-hmXgjhJHhhI125s,6392
@@ -218,8 +218,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
218
218
  pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
219
219
  pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
220
220
  pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
221
- pyglove-0.5.0.dev202510160810.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
222
- pyglove-0.5.0.dev202510160810.dist-info/METADATA,sha256=65NWYsHR82HetqC5evpjVKFUh_P8ARXiZkKLwu5MOss,7089
223
- pyglove-0.5.0.dev202510160810.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
224
- pyglove-0.5.0.dev202510160810.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
225
- pyglove-0.5.0.dev202510160810.dist-info/RECORD,,
221
+ pyglove-0.5.0.dev202510170226.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
222
+ pyglove-0.5.0.dev202510170226.dist-info/METADATA,sha256=Hk2SsgTsNgeAfgxQYyDRdCRj2I9g7Tq9sUdwdQ3GuMM,7089
223
+ pyglove-0.5.0.dev202510170226.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
224
+ pyglove-0.5.0.dev202510170226.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
225
+ pyglove-0.5.0.dev202510170226.dist-info/RECORD,,