pyglove 0.4.5.dev202501020808__py3-none-any.whl → 0.4.5.dev202501030808__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.
pyglove/core/__init__.py CHANGED
@@ -323,6 +323,12 @@ views.html.controls = controls
323
323
 
324
324
  from pyglove.core import io
325
325
 
326
+ #
327
+ # Symbols from `coding` sub-module.
328
+ #
329
+ #
330
+
331
+ from pyglove.core import coding
326
332
 
327
333
  #
328
334
  # Symbols from `logging.py`.
@@ -0,0 +1,26 @@
1
+ # Copyright 2024 The PyGlove Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # pylint: disable=line-too-long
15
+ """Code generation utilities."""
16
+
17
+ # pylint: enable=line-too-long
18
+ # pylint: disable=g-bad-import-order
19
+ # pylint: disable=g-importing-member
20
+
21
+ from pyglove.core.coding.function_generation import NO_TYPE_ANNOTATION
22
+ from pyglove.core.coding.function_generation import make_function
23
+
24
+ # pylint: disable=line-too-long
25
+ # pylint: enable=g-bad-import-order
26
+ # pylint: enable=g-importing-member
@@ -11,10 +11,16 @@
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
- """Utilities for code generation."""
14
+ """Utilities for function generation."""
15
15
 
16
16
  from typing import Any, Dict, List, Optional
17
- from pyglove.core.object_utils.missing import MISSING_VALUE
17
+
18
+
19
+ class _NoTypeAnnotation:
20
+ """Placeholder for no type annotation."""
21
+
22
+
23
+ NO_TYPE_ANNOTATION = _NoTypeAnnotation()
18
24
 
19
25
 
20
26
  def make_function(
@@ -24,11 +30,11 @@ def make_function(
24
30
  *,
25
31
  exec_globals: Optional[Dict[str, Any]] = None,
26
32
  exec_locals: Optional[Dict[str, Any]] = None,
27
- return_type: Any = MISSING_VALUE):
33
+ return_type: Any = NO_TYPE_ANNOTATION):
28
34
  """Creates a function dynamically from source."""
29
35
  if exec_locals is None:
30
36
  exec_locals = {}
31
- if return_type != MISSING_VALUE:
37
+ if return_type != NO_TYPE_ANNOTATION:
32
38
  exec_locals['_return_type'] = return_type
33
39
  return_annotation = '->_return_type'
34
40
  else:
@@ -1,4 +1,4 @@
1
- # Copyright 2022 The PyGlove Authors
1
+ # Copyright 2024 The PyGlove Authors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -11,20 +11,18 @@
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
- """Tests for pyglove.object_utils.codegen."""
15
-
16
14
  import inspect
17
15
  import typing
18
16
  import unittest
19
17
 
20
- from pyglove.core.object_utils import codegen
18
+ from pyglove.core.coding import function_generation
21
19
 
22
20
 
23
21
  class MakeFunctionTest(unittest.TestCase):
24
- """Tests for codegen.make_function."""
22
+ """Tests for function_generation.make_function."""
25
23
 
26
24
  def test_make_function_with_type_annotations(self):
27
- func = codegen.make_function(
25
+ func = function_generation.make_function(
28
26
  'foo',
29
27
  ['x: typing.Optional[int]', 'y: int = 0'],
30
28
  ['return x + y'],
@@ -41,7 +39,7 @@ class MakeFunctionTest(unittest.TestCase):
41
39
  self.assertEqual(func(1, 2), 3)
42
40
 
43
41
  def test_make_function_without_type_annotations(self):
44
- func = codegen.make_function(
42
+ func = function_generation.make_function(
45
43
  'foo',
46
44
  ['x', 'y'],
47
45
  ['return x + y'])
@@ -126,9 +126,6 @@ from pyglove.core.object_utils.common_traits import Functor
126
126
  from pyglove.core.object_utils.common_traits import explicit_method_override
127
127
  from pyglove.core.object_utils.common_traits import ensure_explicit_method_override
128
128
 
129
- # Handling code generation.
130
- from pyglove.core.object_utils.codegen import make_function
131
-
132
129
  # Handling thread local values.
133
130
  from pyglove.core.object_utils.thread_local import thread_local_value_scope
134
131
  from pyglove.core.object_utils.thread_local import thread_local_has
@@ -19,6 +19,7 @@ import inspect
19
19
  import typing
20
20
  from typing import Any, Dict, Iterator, List, Optional, Sequence, Union
21
21
 
22
+ from pyglove.core import coding
22
23
  from pyglove.core import object_utils
23
24
  from pyglove.core import typing as pg_typing
24
25
  from pyglove.core.symbolic import base
@@ -504,7 +505,7 @@ class Object(base.Symbolic, metaclass=ObjectMeta):
504
505
  def _create_sym_attribute(cls, attr_name, field):
505
506
  """Customizable trait: template of single symbolic attribute."""
506
507
  return property(
507
- object_utils.make_function(
508
+ coding.make_function(
508
509
  attr_name,
509
510
  ['self'],
510
511
  [f"return self.sym_inferred('{attr_name}')"],
@@ -21,6 +21,7 @@ import types
21
21
  import typing
22
22
  from typing import Any, Callable, Dict, List, Optional, Union
23
23
 
24
+ from pyglove.core import coding
24
25
  from pyglove.core import object_utils
25
26
  from pyglove.core.typing import class_schema
26
27
  from pyglove.core.typing import key_specs as ks
@@ -753,14 +754,15 @@ class Signature(object_utils.Formattable):
753
754
  )
754
755
 
755
756
  # Generate function.
756
- fn = object_utils.make_function(
757
+ fn = coding.make_function(
757
758
  self.name,
758
759
  args=args,
759
760
  body=body,
760
761
  exec_globals=exec_globals,
761
762
  exec_locals=exec_locals,
762
763
  return_type=getattr(
763
- self.return_value, 'annotation', object_utils.MISSING_VALUE))
764
+ self.return_value, 'annotation', coding.NO_TYPE_ANNOTATION)
765
+ )
764
766
  fn.__module__ = self.module_name
765
767
  fn.__name__ = self.name
766
768
  fn.__qualname__ = self.qualname
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyglove
3
- Version: 0.4.5.dev202501020808
3
+ Version: 0.4.5.dev202501030808
4
4
  Summary: PyGlove: A library for manipulating Python objects.
5
5
  Home-page: https://github.com/google/pyglove
6
6
  Author: PyGlove Authors
@@ -1,7 +1,10 @@
1
1
  pyglove/__init__.py,sha256=YPUWALRDu4QuI7N3TUmVaVr513hUt0qXrjY582I1q5c,1352
2
- pyglove/core/__init__.py,sha256=FDGkzVlLR0FohA8_ZBFrxhEYxQWAGKe72mjUDjE_SDY,9293
2
+ pyglove/core/__init__.py,sha256=pEvIMPH7pu03Ir1rnLWCuWbriobwBTYACP22fMIg-8U,9368
3
3
  pyglove/core/logging.py,sha256=Sr5nLyUQmc4CAEYAq8qbP3ghpjmpz2sOuhq2A0tgQ6I,2456
4
4
  pyglove/core/logging_test.py,sha256=QM59tCAFOUKm4gM6ef_9eG1AvSGEYRDLrrprUQyslcA,1956
5
+ pyglove/core/coding/__init__.py,sha256=nVKjJQYhvzJNr1zj0GuCsz_ltGLqhQEtBQj0zPiOkqA,998
6
+ pyglove/core/coding/function_generation.py,sha256=2fCqcdcizVYtGYE6QGpw5m1kuH9Fp0OF4BjyJ4en6tw,1636
7
+ pyglove/core/coding/function_generation_test.py,sha256=kbSwmZF8Vog0R0OTSpuzPblEbMLoRJ1TigeIrwDhHS8,2161
5
8
  pyglove/core/detouring/__init__.py,sha256=ck_n2VSuU31HNVYQkbG4Zvnx90mNYtSVc2StN3rXbU8,1891
6
9
  pyglove/core/detouring/class_detour.py,sha256=ejuUr7UfRU3l9PrDxD0dpKmt2iqdDU6liHdebA1jEfQ,13312
7
10
  pyglove/core/detouring/class_detour_test.py,sha256=9aAK6qPiT0_HJe5oUpqMVTpoHv0wr_h6c4gWYKMTJoM,5507
@@ -47,9 +50,7 @@ pyglove/core/io/file_system.py,sha256=ps5SVckgFsrZk4xCu37iXkeIrvydLzLs9NsF14VzEc
47
50
  pyglove/core/io/file_system_test.py,sha256=FX0ySuh_Xcg1RO68do7ikD4pvslKUzfSpwZ6P4wIP7c,8691
48
51
  pyglove/core/io/sequence.py,sha256=7QWMGXPtJzHyGPgqkT3yJ01FxKJ4mP4lF5HRDiIHNbQ,8165
49
52
  pyglove/core/io/sequence_test.py,sha256=6tmnS7frBuDR8ussT5jugeh23TDsPDrDnbfxHh81Gy4,3891
50
- pyglove/core/object_utils/__init__.py,sha256=bFyt-_uNzpOjJGDfYFTRP1kV6rL4du9xGx_OaFMcIxI,8758
51
- pyglove/core/object_utils/codegen.py,sha256=HQlpjz42oh_2lrGSflwuAcEneE9Bv8pgPahQzvJm1KI,1568
52
- pyglove/core/object_utils/codegen_test.py,sha256=ThPVyE805plNvM8vwlDxMrcjV-GGdDgbBLSqSOpCvJ0,2166
53
+ pyglove/core/object_utils/__init__.py,sha256=i-WXhMKZWV2yC2u7TpzhIT9XraTdx8BzT5pqdfaK_yc,8669
53
54
  pyglove/core/object_utils/common_traits.py,sha256=PWxOgPhG5H60ZwfO8xNAEGRjFUqqDZQBWQYomOfvdy8,3640
54
55
  pyglove/core/object_utils/common_traits_test.py,sha256=wIeVsF3kon9K0Kbblcaib9hBJeZ76LyGZDD-5A1BD9w,1182
55
56
  pyglove/core/object_utils/docstr_utils.py,sha256=5BY40kXozPKVGOB0eN8jy1P5_GHIzqFJ9FXAu_kzxaw,5119
@@ -98,7 +99,7 @@ pyglove/core/symbolic/inferred.py,sha256=jGCKXLkYGDs-iUflR57UWrCrOQIpkpv5kHVyj-J
98
99
  pyglove/core/symbolic/inferred_test.py,sha256=G6uPykONcChvs6vZujXHSWaYfjewLTVBscMqzzKNty0,1270
99
100
  pyglove/core/symbolic/list.py,sha256=63v4Ph0FdkoCDj1FjwcmjUHGZSJLBLxaTKcGg7PdghE,30345
100
101
  pyglove/core/symbolic/list_test.py,sha256=yHYAJhe_EYwtU9p8eDztSXNBjnAGKe0UDN5U6S-xDr8,60627
101
- pyglove/core/symbolic/object.py,sha256=hy2waFCo3NFPzymXbDHGBUqW2EhEmF9fE4Crp9Hnewc,42137
102
+ pyglove/core/symbolic/object.py,sha256=cf9GELfLEZSESxQU9BlA06yTtv2XWsnwXgONjkfOzNo,42163
102
103
  pyglove/core/symbolic/object_test.py,sha256=WNp8lB202EMn7RDJbMAV_VVdtjg9MB3HKTgaJN8GTuw,93617
103
104
  pyglove/core/symbolic/origin.py,sha256=5bH1jZvFHY5jwku32vDm8Bj2i-buv-YNuzOOsA5GlSA,6177
104
105
  pyglove/core/symbolic/origin_test.py,sha256=dU_ZGrGDetM_lYVMn3wQO0d367_t_t8eESe3NrKPBNE,3159
@@ -123,7 +124,7 @@ pyglove/core/typing/annotation_conversion.py,sha256=rNYOyC0ury-kiDpxRqABz-E3ll7r
123
124
  pyglove/core/typing/annotation_conversion_test.py,sha256=tZheqbLWbr76WBIDOplLtY3yznMc4m9u7KCznWEJdEs,11660
124
125
  pyglove/core/typing/callable_ext.py,sha256=1OM770LhT46qjhriKEgyDHp6whAGG0inobPbFUM2J8k,9218
125
126
  pyglove/core/typing/callable_ext_test.py,sha256=TnWKU4_ZjvpbHZFtFHgFvCMDiCos8VmLlODcM_7Xg8M,10156
126
- pyglove/core/typing/callable_signature.py,sha256=MAH7isqhxXp8QdMw8jqxqWbsKs2jMh7uJlFIBL0tTQk,27242
127
+ pyglove/core/typing/callable_signature.py,sha256=35cYIWMUR0Qr8gkbsx1kf_HcWxNPiwDvV3oQMULsbDs,27272
127
128
  pyglove/core/typing/callable_signature_test.py,sha256=BYdn0i7nd0ITkACnR1RNtnmpXiE0MfpBrlQ7-yWSxYE,25223
128
129
  pyglove/core/typing/class_schema.py,sha256=ls_pg4MgwvV4s5gLnsjqDkiP3O2Fg0sWdjL1NVD-iyE,53273
129
130
  pyglove/core/typing/class_schema_test.py,sha256=1DvJTss20jzjruTnB4CuW6ozO6Hcs6TIN-xsJzEQkCM,29244
@@ -196,8 +197,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
196
197
  pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
197
198
  pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
198
199
  pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
199
- pyglove-0.4.5.dev202501020808.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
200
- pyglove-0.4.5.dev202501020808.dist-info/METADATA,sha256=SzlGZ_jGtsrQA5MkWJ4kyQI7wIF_aDR97J6qkoh11uw,6828
201
- pyglove-0.4.5.dev202501020808.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
202
- pyglove-0.4.5.dev202501020808.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
203
- pyglove-0.4.5.dev202501020808.dist-info/RECORD,,
200
+ pyglove-0.4.5.dev202501030808.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
201
+ pyglove-0.4.5.dev202501030808.dist-info/METADATA,sha256=WtNne1_ODAbjcjCcuix0uIdfDwv7PMbcwCmORPcWiYI,6828
202
+ pyglove-0.4.5.dev202501030808.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
203
+ pyglove-0.4.5.dev202501030808.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
204
+ pyglove-0.4.5.dev202501030808.dist-info/RECORD,,