Skip to content

Commit de94f4f

Browse files
jbmscopybara-github
authored andcommitted
Fix kvstore type annotations and move py.typed file to correct location
PiperOrigin-RevId: 836860557 Change-Id: Ic809c14f2a1ffdba451e05907840581a44e468db
1 parent 49988d1 commit de94f4f

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

python/tensorstore/__init__.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5438,7 +5438,7 @@ class KvStore:
54385438

54395439
__hash__: typing.ClassVar[None] = None
54405440

5441-
def __add__(self, suffix: str) -> KvStore.Spec:
5441+
def __add__(self, suffix: str | bytes) -> KvStore.Spec:
54425442
"""
54435443
Returns a key-value store with the suffix appended to the path.
54445444
@@ -5507,7 +5507,7 @@ class KvStore:
55075507
KvStore.Spec({'driver': 'file', 'path': 'tmp/data/'})
55085508
"""
55095509

5510-
def __truediv__(self, component: str) -> KvStore.Spec:
5510+
def __truediv__(self, component: str | bytes) -> KvStore.Spec:
55115511
"""
55125512
Returns a key-value store with an additional path component joined to the path.
55135513
@@ -5674,7 +5674,7 @@ class KvStore:
56745674
"""
56755675

56765676
@path.setter
5677-
def path(self, arg1: str) -> None: ...
5677+
def path(self, arg1: str | bytes) -> None: ...
56785678

56795679
@property
56805680
def url(self) -> str:
@@ -5839,7 +5839,7 @@ class KvStore:
58395839
Operators
58405840
"""
58415841

5842-
def __contains__(self, key: str) -> bool:
5842+
def __contains__(self, key: str | bytes) -> bool:
58435843
"""
58445844
Synchronously checks if the given key is present.
58455845
@@ -5881,7 +5881,7 @@ class KvStore:
58815881

58825882
def __copy__(self) -> KvStore: ...
58835883

5884-
def __delitem__(self, key: str) -> None:
5884+
def __delitem__(self, key: str | bytes) -> None:
58855885
"""
58865886
Synchronously deletes a single key.
58875887

python/tensorstore/kvstore.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,12 @@ See also:
727727

728728
cls.def(
729729
"__contains__",
730-
[](const Self& self, std::string_view key) -> bool {
730+
[](const Self& self, StrOrBytesView key) -> bool {
731731
kvstore::ReadOptions options;
732732
options.byte_range = OptionalByteRangeRequest::Stat();
733733
auto result = ValueOrThrow(InterruptibleWait([&]() {
734734
ScopedPyCriticalSection cs(reinterpret_cast<const PyObject*>(&self));
735-
return kvstore::Read(self.value, key, std::move(options));
735+
return kvstore::Read(self.value, key.value, std::move(options));
736736
}()));
737737
return result.has_value();
738738
},
@@ -904,10 +904,10 @@ See also:
904904

905905
cls.def(
906906
"__delitem__",
907-
[](const Self& self, std::string_view key) {
907+
[](const Self& self, StrOrBytesView key) {
908908
ValueOrThrow(InterruptibleWait([&]() {
909909
ScopedPyCriticalSection cs(reinterpret_cast<const PyObject*>(&self));
910-
return kvstore::Write(self.value, key, std::nullopt);
910+
return kvstore::Write(self.value, key.value, std::nullopt);
911911
}()));
912912
},
913913
py::arg("key"), R"(
@@ -1353,9 +1353,9 @@ Modifies a spec.
13531353
ScopedPyCriticalSection cs(reinterpret_cast<const PyObject*>(&self));
13541354
return self.value.path;
13551355
},
1356-
[](Self& self, std::string_view path) {
1356+
[](Self& self, StrOrBytesView path) {
13571357
ScopedPyCriticalSection cs(reinterpret_cast<PyObject*>(&self));
1358-
self.value.path = path;
1358+
self.value.path = path.value;
13591359
},
13601360
R"(
13611361
Path prefix within the base key-value store.
@@ -1395,10 +1395,10 @@ Path prefix within the base key-value store.
13951395

13961396
cls.def(
13971397
"__add__",
1398-
[](const Self& self, std::string_view suffix) -> kvstore::Spec {
1398+
[](const Self& self, StrOrBytesView suffix) -> kvstore::Spec {
13991399
ScopedPyCriticalSection cs(reinterpret_cast<const PyObject*>(&self));
14001400
auto new_spec = self.value;
1401-
new_spec.AppendSuffix(suffix);
1401+
new_spec.AppendSuffix(suffix.value);
14021402
return new_spec;
14031403
},
14041404
py::arg("suffix"), R"(
@@ -1421,10 +1421,10 @@ ensure there is a :python:`'/'` separator, use :py:obj:`.__truediv__` instead.
14211421

14221422
cls.def(
14231423
"__truediv__",
1424-
[](const Self& self, std::string_view component) -> kvstore::Spec {
1424+
[](const Self& self, StrOrBytesView component) -> kvstore::Spec {
14251425
ScopedPyCriticalSection cs(reinterpret_cast<const PyObject*>(&self));
14261426
auto new_spec = self.value;
1427-
new_spec.AppendPathComponent(component);
1427+
new_spec.AppendPathComponent(component.value);
14281428
return new_spec;
14291429
},
14301430
py::arg("component"), R"(
File renamed without changes.

0 commit comments

Comments
 (0)