pyglove 0.5.0.dev202510230811__py3-none-any.whl → 0.5.0.dev202511080809__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.

@@ -506,8 +506,7 @@ class ListTest(unittest.TestCase):
506
506
  def test_index(self):
507
507
  sl = List([0, 1, 2, 1])
508
508
  self.assertEqual(sl.index(1), 1)
509
- with self.assertRaisesRegex(
510
- ValueError, '3 is not in list'):
509
+ with self.assertRaisesRegex(ValueError, '.* not in list'):
511
510
  _ = sl.index(3)
512
511
 
513
512
  # Index of inferred value is based on its symbolic form.
@@ -16,6 +16,7 @@
16
16
  import builtins
17
17
  import collections
18
18
  import inspect
19
+ import sys
19
20
  import types
20
21
  import typing
21
22
 
@@ -197,6 +198,8 @@ def annotation_from_str(
197
198
  def _resolve(type_id: str):
198
199
 
199
200
  def _as_forward_ref() -> typing.ForwardRef:
201
+ if sys.version_info >= (3, 14):
202
+ return typing.ForwardRef(type_id) # pytype: disable=not-callable
200
203
  return typing.ForwardRef(type_id, False, parent_module) # pytype: disable=not-callable
201
204
 
202
205
  def _resolve_name(name: str, parent_obj: typing.Any):
@@ -34,6 +34,12 @@ class Foo:
34
34
  _MODULE = sys.modules[__name__]
35
35
 
36
36
 
37
+ def typing_forward_ref(name: str) -> typing.ForwardRef:
38
+ if sys.version_info >= (3, 14):
39
+ return typing.ForwardRef(name)
40
+ return typing.ForwardRef(name, False, _MODULE)
41
+
42
+
37
43
  class AnnotationFromStrTest(unittest.TestCase):
38
44
  """Tests for annotation_from_str."""
39
45
 
@@ -69,7 +75,7 @@ class AnnotationFromStrTest(unittest.TestCase):
69
75
  )
70
76
  self.assertEqual(
71
77
  annotation_conversion.annotation_from_str('list[Foo.Baz]', _MODULE),
72
- list[typing.ForwardRef('Foo.Baz', False, _MODULE)]
78
+ list[typing_forward_ref('Foo.Baz')]
73
79
  )
74
80
 
75
81
  def test_generic_types(self):
@@ -138,18 +144,12 @@ class AnnotationFromStrTest(unittest.TestCase):
138
144
  self.assertEqual(
139
145
  annotation_conversion.annotation_from_str(
140
146
  'AAA', _MODULE),
141
- typing.ForwardRef(
142
- 'AAA', False, _MODULE
143
- )
147
+ typing_forward_ref('AAA')
144
148
  )
145
149
  self.assertEqual(
146
150
  annotation_conversion.annotation_from_str(
147
151
  'typing.List[AAA]', _MODULE),
148
- typing.List[
149
- typing.ForwardRef(
150
- 'AAA', False, _MODULE
151
- )
152
- ]
152
+ typing.List[typing_forward_ref('AAA')]
153
153
  )
154
154
 
155
155
  def test_reloading(self):
@@ -157,20 +157,12 @@ class AnnotationFromStrTest(unittest.TestCase):
157
157
  self.assertEqual(
158
158
  annotation_conversion.annotation_from_str(
159
159
  'typing.List[Foo]', _MODULE),
160
- typing.List[
161
- typing.ForwardRef(
162
- 'Foo', False, _MODULE
163
- )
164
- ]
160
+ typing.List[typing_forward_ref('Foo')]
165
161
  )
166
162
  self.assertEqual(
167
163
  annotation_conversion.annotation_from_str(
168
164
  'typing.List[Foo.Bar]', _MODULE),
169
- typing.List[
170
- typing.ForwardRef(
171
- 'Foo.Bar', False, _MODULE
172
- )
173
- ]
165
+ typing.List[typing_forward_ref('Foo.Bar')]
174
166
  )
175
167
  delattr(_MODULE, '__reloading__')
176
168
 
@@ -15,6 +15,7 @@
15
15
 
16
16
  import calendar
17
17
  import datetime
18
+ import sys
18
19
  from typing import Any, Callable, Optional, Tuple, Type, Union
19
20
 
20
21
  from pyglove.core import utils
@@ -135,9 +136,22 @@ def _register_builtin_converters():
135
136
  register_converter(int, float, float)
136
137
 
137
138
  # int <=> datetime.datetime.
138
- register_converter(int, datetime.datetime, datetime.datetime.utcfromtimestamp)
139
- register_converter(datetime.datetime, int,
140
- lambda x: calendar.timegm(x.timetuple()))
139
+ if sys.version_info >= (3, 11):
140
+ register_converter(
141
+ int,
142
+ datetime.datetime,
143
+ lambda x: datetime.datetime.fromtimestamp(x, datetime.UTC)
144
+ )
145
+ else:
146
+ register_converter(
147
+ int, datetime.datetime, datetime.datetime.utcfromtimestamp
148
+ )
149
+
150
+ register_converter(
151
+ datetime.datetime,
152
+ int,
153
+ lambda x: calendar.timegm(x.timetuple())
154
+ )
141
155
 
142
156
  # string <=> KeyPath.
143
157
  register_converter(str, utils.KeyPath, utils.KeyPath.parse)
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
  import calendar
15
15
  import datetime
16
+ import sys
16
17
  import typing
17
18
  import unittest
18
19
 
@@ -130,12 +131,16 @@ class BuiltInConversionsTest(unittest.TestCase):
130
131
  def test_datetime_to_int(self):
131
132
  """Test built-in converter between int and datetime.datetime."""
132
133
  timestamp = calendar.timegm(datetime.datetime.now().timetuple())
133
- now = datetime.datetime.utcfromtimestamp(timestamp)
134
+ if sys.version_info >= (3, 11):
135
+ now = datetime.datetime.fromtimestamp(timestamp, datetime.UTC)
136
+ else:
137
+ now = datetime.datetime.utcfromtimestamp(timestamp)
134
138
  self.assertEqual(vs.Object(datetime.datetime).apply(timestamp), now)
135
139
  self.assertEqual(vs.Int().apply(now), timestamp)
136
140
  self.assertEqual(
137
141
  type_conversion.get_json_value_converter(datetime.datetime)(now),
138
- timestamp)
142
+ timestamp
143
+ )
139
144
 
140
145
  def test_keypath_to_str(self):
141
146
  """Test built-in converter between string and KeyPath."""
@@ -271,7 +271,8 @@ class JSONConvertibleTest(unittest.TestCase):
271
271
  self.assert_conversion_is(typing.List[typing.List[int]])
272
272
  self.assert_conversion_is(typing.Annotated[int, 'abc'])
273
273
  self.assert_conversion_is(typing.Dict[str, typing.Any])
274
- self.assert_conversion_is(typing.Union[int, str])
274
+ # From Python 3.14, union no longer preserves `is` identity.
275
+ self.assert_conversion_equal(typing.Union[int, str])
275
276
  self.assert_conversion_is(typing.Sequence[int])
276
277
  self.assert_conversion_is(typing.Set[int])
277
278
  self.assert_conversion_is(typing.FrozenSet[int])
@@ -158,6 +158,39 @@ class TabControl(HtmlControl):
158
158
  position='beforebegin',
159
159
  )
160
160
 
161
+ def remove(self, index_or_name: Union[int, str]) -> Tab:
162
+ """Removes a tab identified by index or name."""
163
+ index = self.indexof(index_or_name)
164
+ if index == -1:
165
+ raise ValueError(f'Tab not found: {index_or_name!r}')
166
+
167
+ with pg_flags.notify_on_change(False):
168
+ tab = self.tabs.pop(index)
169
+
170
+ self._run_javascript(
171
+ f"""
172
+ const button = document.querySelectorAll('#{self.element_id()}-button-group > .tab-button')[{index}];
173
+ if (button) {{
174
+ button.remove();
175
+ }}
176
+ const content = document.querySelectorAll('#{self.element_id()}-content-group > .tab-content')[{index}];
177
+ if (content) {{
178
+ content.remove();
179
+ }}
180
+ """
181
+ )
182
+
183
+ if not self.tabs:
184
+ self._sync_members(selected=0)
185
+ return tab
186
+
187
+ if self.selected == index:
188
+ new_selected = index - 1 if index == len(self.tabs) else index
189
+ self.select(max(0, new_selected))
190
+ elif self.selected > index:
191
+ self._sync_members(selected=self.selected - 1)
192
+ return tab
193
+
161
194
  def indexof(self, index_or_name: Union[int, str]) -> int:
162
195
  if isinstance(index_or_name, int):
163
196
  index = index_or_name
@@ -154,6 +154,43 @@ class TabControlTest(unittest.TestCase):
154
154
  self.assertEqual(len(scripts), 1)
155
155
  self.assertEqual(tab.selected, 1)
156
156
 
157
+ def test_remove(self):
158
+ tabs = [tab_lib.Tab(l, l, name=l) for l in ['a', 'b', 'c', 'd']]
159
+ tc = tab_lib.TabControl(tabs, selected='c')
160
+ self.assertEqual([t.name for t in tc.tabs], ['a', 'b', 'c', 'd'])
161
+ self.assertEqual(tc.selected, 2)
162
+
163
+ # Trigger rendering so scripts are tracked.
164
+ _ = tc.to_html()
165
+ with tc.track_scripts() as scripts:
166
+ tc.remove('b')
167
+ self.assertEqual(len(scripts), 1)
168
+ self.assertEqual([t.name for t in tc.tabs], ['a', 'c', 'd'])
169
+ self.assertEqual(tc.selected, 1)
170
+
171
+ with tc.track_scripts() as scripts:
172
+ # Remove currently selected tab 'c'
173
+ tc.remove('c')
174
+ # 1 script for remove, 1 for select.
175
+ self.assertEqual(len(scripts), 2)
176
+ self.assertEqual([t.name for t in tc.tabs], ['a', 'd'])
177
+ self.assertEqual(tc.selected, 1)
178
+
179
+ with tc.track_scripts() as scripts:
180
+ tc.remove(1)
181
+ self.assertEqual(len(scripts), 2)
182
+ self.assertEqual([t.name for t in tc.tabs], ['a'])
183
+ self.assertEqual(tc.selected, 0)
184
+
185
+ with tc.track_scripts() as scripts:
186
+ tc.remove('a')
187
+ self.assertEqual(len(scripts), 1)
188
+ self.assertEqual(tc.tabs, [])
189
+ self.assertEqual(tc.selected, 0)
190
+
191
+ with self.assertRaisesRegex(ValueError, 'Tab not found'):
192
+ tc.remove('x')
193
+
157
194
 
158
195
  if __name__ == '__main__':
159
196
  unittest.main()
@@ -57,7 +57,7 @@ class NextValue(base.Mutator):
57
57
  """A mutator to increase current DNA by 1."""
58
58
 
59
59
  def mutate(self, dna, step):
60
- return dna.next_dna()
60
+ return dna.next_dna() or dna
61
61
 
62
62
 
63
63
  def search_space():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyglove
3
- Version: 0.5.0.dev202510230811
3
+ Version: 0.5.0.dev202511080809
4
4
  Summary: PyGlove: A library for manipulating Python objects.
5
5
  Home-page: https://github.com/google/pyglove
6
6
  Author: PyGlove Authors
@@ -91,7 +91,7 @@ pyglove/core/symbolic/functor_test.py,sha256=9c5_7OBKNVNbYC7IaVQB6c5ks2v00qQ36oi
91
91
  pyglove/core/symbolic/inferred.py,sha256=E4zgphg6NNZad9Fl3jdHQOMZeqEp9XHq5OUYqXEmwZQ,3178
92
92
  pyglove/core/symbolic/inferred_test.py,sha256=G6uPykONcChvs6vZujXHSWaYfjewLTVBscMqzzKNty0,1270
93
93
  pyglove/core/symbolic/list.py,sha256=CRDoBxYJsmNly1MxhY5vO0wp6EUTnxze6-2O9vXHna4,30717
94
- pyglove/core/symbolic/list_test.py,sha256=Q3kqQ6aaQ40Nw6osSxrGk4N_E1lGZyvwdvxZgLRwMS0,61954
94
+ pyglove/core/symbolic/list_test.py,sha256=sH3wuJB6SqXVefJEPmzGVfoXc-ZiJ1ZTV4-O88LFuaM,61943
95
95
  pyglove/core/symbolic/object.py,sha256=UgDgKdcYDYX3J51EMQamdwaXHkG4SHPunAGkSuHuTa0,42768
96
96
  pyglove/core/symbolic/object_test.py,sha256=rDP7lcQZTFdQCqeaNYs7ZfwvGanzHz7CHM33NCmRIFk,94391
97
97
  pyglove/core/symbolic/origin.py,sha256=OSWMKjvPcISOXrzuX3lCQC8m_qaGl-9INsIB81erUnU,6124
@@ -113,8 +113,8 @@ pyglove/core/tuning/sample_test.py,sha256=JqwDPy3EPC_VjU9dipk90jj1kovZB3Zb9hAjAl
113
113
  pyglove/core/typing/__init__.py,sha256=u2YSrSi8diTkQn8_1J2hEpk5o7zDhx2tU_oRuS-k1XU,14580
114
114
  pyglove/core/typing/annotated.py,sha256=llaajIDj9GK-4kUGJoO4JsHU6ESPOra2SZ-jG6xmsOQ,3203
115
115
  pyglove/core/typing/annotated_test.py,sha256=p1qid3R-jeiOTTxOVq6hXW8XFvn-h1cUzJWISPst2l8,2484
116
- pyglove/core/typing/annotation_conversion.py,sha256=hi4LcRXwYzspHAKZ0rtXlq2dQyAmo9GXrm_HCJAGl34,15657
117
- pyglove/core/typing/annotation_conversion_test.py,sha256=g66iyt3ti_pskIXndk4DiKgO8j8aMYOe2nPKXszlXmw,17675
116
+ pyglove/core/typing/annotation_conversion.py,sha256=pnm6dZbn_nsTCreyarspkwpsdteMb8uFT2TLtblq_0M,15780
117
+ pyglove/core/typing/annotation_conversion_test.py,sha256=N49ZuzsmaqVi23wszDpfwcJApr2-Pk2E_ELrjssSQb0,17598
118
118
  pyglove/core/typing/annotation_future_test.py,sha256=tAVuzWNfW8R4e4l7fx88Q4nJDM2LPUogNKNAIIPAEWQ,3959
119
119
  pyglove/core/typing/callable_ext.py,sha256=PiBQWPeUAH7Lgmf2xKCZqgK7N0OSrTdbnEkV8Ph31OA,9127
120
120
  pyglove/core/typing/callable_ext_test.py,sha256=TnWKU4_ZjvpbHZFtFHgFvCMDiCos8VmLlODcM_7Xg8M,10156
@@ -130,8 +130,8 @@ pyglove/core/typing/json_schema_test.py,sha256=ZxMO2xgKiELNDzoQ84cmXsyCtFA0Ltn1I
130
130
  pyglove/core/typing/key_specs.py,sha256=-7xjCuUGoQgD0sMafsRFNlw3S4f1r-7t5OO4ev5bbeI,9225
131
131
  pyglove/core/typing/key_specs_test.py,sha256=5zornpyHMAYoRaG8KDXHiQ3obu9UfRp3399lBeUNTPk,6499
132
132
  pyglove/core/typing/pytype_support.py,sha256=lyX11WVbCwoOi5tTQ90pEOS-yvo_6iEi7Lxbp-nXu2A,2069
133
- pyglove/core/typing/type_conversion.py,sha256=0L4Cbsw_QiM-gpsn-4y-XLEIvwiUB16Clj9gCtoC_Xc,5224
134
- pyglove/core/typing/type_conversion_test.py,sha256=BhASOGvtKXmYLWKCELU1RVB_Nmt1V-saSkGogvsNL7E,5342
133
+ pyglove/core/typing/type_conversion.py,sha256=S_57FU-9DOk-MTE-1Mh31FMshaA3IoKiSDsoKxGxGv4,5432
134
+ pyglove/core/typing/type_conversion_test.py,sha256=rK0lAjLi1azKY4ZltquIsCpKh20EtYSIekArnqI6ThQ,5475
135
135
  pyglove/core/typing/typed_missing.py,sha256=-l1omAu0jBZv5BnsFYXBqfvQwVBnmPh_X1wcIKD9bOk,2734
136
136
  pyglove/core/typing/typed_missing_test.py,sha256=TCNsb1SRpFaVdxYn2mB_yaLuja8w5Qn5NP7uGiZVBWs,2301
137
137
  pyglove/core/typing/value_specs.py,sha256=8E83QDZMb3lMXhgzfVNt9u6Bg3NPkvpjLXetjkps8UU,103263
@@ -150,7 +150,7 @@ pyglove/core/utils/formatting_test.py,sha256=hhg-nL6DyE5A2QA92ALHK5QtfAYKfPpTbBA
150
150
  pyglove/core/utils/hierarchical.py,sha256=jwB-0FhqOspAymAkvJphRhPTQEsoShmKupCZpU3Vip4,19690
151
151
  pyglove/core/utils/hierarchical_test.py,sha256=f382DMJPa_bavJGGQDjuw-hWcafUg5bkQCPX-nbzeiI,21077
152
152
  pyglove/core/utils/json_conversion.py,sha256=V7wUviGKhEPWi1gtCGSDXXvBzV6cO7CvmEiGDZ2jWFY,34643
153
- pyglove/core/utils/json_conversion_test.py,sha256=6afuPJxBXIO-OxFzJBkv1MZqNX-44HIBD6YJjwxXSbs,13412
153
+ pyglove/core/utils/json_conversion_test.py,sha256=VB0_QKPqVFgiWilkm1OPH6hShjXIro0yLep1ftIucew,13480
154
154
  pyglove/core/utils/missing.py,sha256=9gslt1lXd1qSEIuAFxUWu30oD-YdYcnm13eau1S9uqY,1445
155
155
  pyglove/core/utils/missing_test.py,sha256=D6-FuVEwCyJemUiPLcwLmwyptqI5Bx0Pfipc2juhKSE,1335
156
156
  pyglove/core/utils/text_color.py,sha256=xcCTCxY2qFNZs_jismMGus8scEXKBpYGAhpAgnz-MHk,4112
@@ -175,8 +175,8 @@ pyglove/core/views/html/controls/label.py,sha256=2u7z_6o-ANf6EbxufFl_fZ1VFSUrjNw
175
175
  pyglove/core/views/html/controls/label_test.py,sha256=_Fi6vMITup8iFYTiU_1w7FZCXaYp1eMmVBxub8JMYbs,5170
176
176
  pyglove/core/views/html/controls/progress_bar.py,sha256=0an0eCbPCDjwrR58C16NwLZ-cf3Oy0wQerLsiNgGHmk,5235
177
177
  pyglove/core/views/html/controls/progress_bar_test.py,sha256=kKOJDZQtBPkmNcgIBrRQkNNzcTm51ojuFBTRUEDSsp0,3506
178
- pyglove/core/views/html/controls/tab.py,sha256=dn2rs6IBqvjtKvk0BC8ypVYqjjHsqJvP_Bh9y94QjMc,10818
179
- pyglove/core/views/html/controls/tab_test.py,sha256=deRXg4LM4dzVgods5HVTXznrOWdddF6wrcl1RuhmRCA,5656
178
+ pyglove/core/views/html/controls/tab.py,sha256=f3ZfYyXfMmERGOXY4a4bxmOhomL3MQONMossaxw8hQw,11851
179
+ pyglove/core/views/html/controls/tab_test.py,sha256=V0HrY0YaGyVlOykMCFg85QSxOq8eBPa3Fqcv2q1c12s,6912
180
180
  pyglove/core/views/html/controls/tooltip.py,sha256=01BbpuM1twf3FYMUT09_Ck5JSSONe8QE9RmyA9nhCnU,3092
181
181
  pyglove/core/views/html/controls/tooltip_test.py,sha256=17BY-WmZKpz9tCbySPcwG6KJyfeE_MeMyKxtfxorBQ0,3194
182
182
  pyglove/ext/__init__.py,sha256=3jp8cJvKW6PENOZlmVAbT0w-GBRn_kjhc0wDX3XjpOE,755
@@ -187,7 +187,7 @@ pyglove/ext/early_stopping/step_wise.py,sha256=P99Z2hODmCNBnR3iVOOj2NCCwveSH6h5V
187
187
  pyglove/ext/early_stopping/step_wise_test.py,sha256=I9DDMrCpDwIWC6mV9w2pDypnrwYnWjg6QXTFNT13cts,9032
188
188
  pyglove/ext/evolution/__init__.py,sha256=lAf4NyxUZRt39kMFFoW_i8-ExigJXakG1-sUREW7jkQ,3214
189
189
  pyglove/ext/evolution/base.py,sha256=I27qJja6MErMs3SyrlBYvmDQ4eTq9dY9RVpscKlwReQ,50090
190
- pyglove/ext/evolution/base_test.py,sha256=yIw4YS60c_MvDj71QkoxX5Y2NLZgGc_KzT_NuHMCXMk,29936
190
+ pyglove/ext/evolution/base_test.py,sha256=HgWSGGHh7nd03IFLln3dKV4TsI1kK4idJd4azAGaxHw,29943
191
191
  pyglove/ext/evolution/hill_climb.py,sha256=Bysi2u4KEM7d9CIPcnvKKgEQHttkaKFkI8xlrNOkBB8,1688
192
192
  pyglove/ext/evolution/hill_climb_test.py,sha256=7snzopGFRgkryNXiDVcHMhtVz6LXLZCOH_tz_t15b4I,3110
193
193
  pyglove/ext/evolution/mutators.py,sha256=ZkNmIf9B2KRP3H7UfML7nkjUYPPgOkm5Fe1kaJQ8W5I,10062
@@ -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.dev202510230811.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
222
- pyglove-0.5.0.dev202510230811.dist-info/METADATA,sha256=ZkvMwTAwqLF4U3t0Pan_ZSsTEI_NR_F4I10F5YbrXOA,7089
223
- pyglove-0.5.0.dev202510230811.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
224
- pyglove-0.5.0.dev202510230811.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
225
- pyglove-0.5.0.dev202510230811.dist-info/RECORD,,
221
+ pyglove-0.5.0.dev202511080809.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
222
+ pyglove-0.5.0.dev202511080809.dist-info/METADATA,sha256=c9ygezDjDTLDFoHpI7h4XQ3T65yZF6OOM2SvDKrIGys,7089
223
+ pyglove-0.5.0.dev202511080809.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
224
+ pyglove-0.5.0.dev202511080809.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
225
+ pyglove-0.5.0.dev202511080809.dist-info/RECORD,,