Skip to content

Commit 6d4d140

Browse files
laramielcopybara-github
authored andcommitted
Update ts.KvStore.ReadResult to use StrOrBytes
PiperOrigin-RevId: 826140753 Change-Id: Id665a7a2d901de1afb44361c655968168849ad67
1 parent 11fa15a commit 6d4d140

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

python/tensorstore/kvstore.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,10 +1713,10 @@ Specifies the result of a read operation.
17131713
void DefineReadResultAttributes(ReadResultCls& cls) {
17141714
using Self = kvstore::ReadResult;
17151715

1716-
cls.def(py::init([](Self::State state, std::string value,
1716+
cls.def(py::init([](Self::State state, StrOrBytes value,
17171717
TimestampedStorageGeneration stamp) {
1718-
return kvstore::ReadResult{state, absl::Cord(std::move(value)),
1719-
std::move(stamp)};
1718+
return kvstore::ReadResult{
1719+
state, absl::Cord(std::move(value.value)), std::move(stamp)};
17201720
}),
17211721
py::arg("state") = Self::State::kUnspecified, py::arg("value") = "",
17221722
py::arg("stamp") = TimestampedStorageGeneration(), R"(
@@ -1733,8 +1733,8 @@ Indicates the interpretation of :py:obj:`.value`.
17331733
cls.def_property(
17341734
"value",
17351735
[](const Self& self) -> py::bytes { return CordToPython(self.value); },
1736-
[](Self& self, std::string value) {
1737-
self.value = absl::Cord(std::move(value));
1736+
[](Self& self, StrOrBytes value) {
1737+
self.value = absl::Cord(std::move(value.value));
17381738
},
17391739
R"(
17401740
Value associated with the key.

python/tensorstore/tests/kvstore_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,17 @@ def update_props() -> None:
298298

299299
def test_kvstore_readresult_concurrent() -> None:
300300
"""Tests concurrent access to KvStore.ReadResult properties."""
301-
rr = ts.KvStore.ReadResult()
301+
gen = ts.KvStore.TimestampedStorageGeneration(b'gen', 1.0)
302+
rr = ts.KvStore.ReadResult('value', b'foo', gen)
302303
stop = threading.Event()
303304

304305
def read_props() -> None:
305306
while not stop.is_set():
307+
_ = rr == ts.KvStore.ReadResult()
306308
_ = rr.state
307309
_ = rr.value
308310
_ = rr.stamp
309-
_ = rr == ts.KvStore.ReadResult()
311+
_ = rr == ts.KvStore.ReadResult('value', 'bar', gen)
310312
_ = f'{rr}'
311313
_ = repr(rr)
312314

0 commit comments

Comments
 (0)