Skip to content

Commit 7ed2b2b

Browse files
Update pybind11 extensions references (#425)
1 parent 0feef4e commit 7ed2b2b

File tree

11 files changed

+101
-80
lines changed

11 files changed

+101
-80
lines changed

src/amulet/core/biome/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Biome(amulet.core.version.PlatformVersionContainer):
2525
"""
2626

2727
@typing.overload
28-
def __eq__(self, arg0: Biome) -> bool: ...
28+
def __eq__(self, other: Biome) -> bool: ...
2929
@typing.overload
30-
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
30+
def __eq__(self, other: typing.Any) -> bool | types.NotImplementedType: ...
3131
def __ge__(self, arg0: Biome) -> bool: ...
3232
def __gt__(self, arg0: Biome) -> bool: ...
3333
def __hash__(self) -> int: ...

src/amulet/core/block/__init__.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class Block(amulet.core.version.PlatformVersionContainer):
7777
"""
7878

7979
@typing.overload
80-
def __eq__(self, arg0: Block) -> bool: ...
80+
def __eq__(self, other: Block) -> bool: ...
8181
@typing.overload
82-
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
82+
def __eq__(self, other: typing.Any) -> bool | types.NotImplementedType: ...
8383
def __ge__(self, arg0: Block) -> bool: ...
8484
def __gt__(self, arg0: Block) -> bool: ...
8585
def __hash__(self) -> int: ...
@@ -216,16 +216,16 @@ class BlockStack:
216216
>>> blocks = list(waterlogged_stone)
217217
"""
218218

219-
def __contains__(self, arg0: typing.Any) -> bool: ...
219+
def __contains__(self, item: typing.Any) -> bool: ...
220220
@typing.overload
221-
def __eq__(self, arg0: BlockStack) -> bool: ...
221+
def __eq__(self, other: BlockStack) -> bool: ...
222222
@typing.overload
223-
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
223+
def __eq__(self, other: typing.Any) -> bool | types.NotImplementedType: ...
224224
def __ge__(self, arg0: BlockStack) -> bool: ...
225225
@typing.overload
226226
def __getitem__(self, arg0: typing.SupportsInt) -> Block: ...
227227
@typing.overload
228-
def __getitem__(self, arg0: slice) -> list: ...
228+
def __getitem__(self, item: slice) -> list[Block]: ...
229229
def __gt__(self, arg0: BlockStack) -> bool: ...
230230
def __hash__(self) -> int: ...
231231
def __init__(self, block: Block, *extra_blocks: Block) -> None: ...
@@ -235,10 +235,10 @@ class BlockStack:
235235
def __lt__(self, arg0: BlockStack) -> bool: ...
236236
def __repr__(self) -> str: ...
237237
def __reversed__(self) -> collections.abc.Iterator[Block]: ...
238-
def count(self, value: typing.Any) -> int: ...
238+
def count(self, value: Block) -> int: ...
239239
def index(
240240
self,
241-
value: typing.Any,
241+
value: Block,
242242
start: typing.SupportsInt = 0,
243243
stop: typing.SupportsInt = 9223372036854775807,
244244
) -> int: ...

src/amulet/core/block/block.py.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <memory>
77
#include <span>
88

9-
#include <amulet/pybind11_extensions/types.hpp>
109
#include <amulet/pybind11_extensions/py_module.hpp>
10+
#include <amulet/pybind11_extensions/types.hpp>
1111

1212
#include <amulet/pybind11_extensions/sequence.hpp>
1313

@@ -278,8 +278,7 @@ void init_block(py::module m_parent)
278278
if (index < 0) {
279279
throw py::index_error("");
280280
}
281-
}
282-
if (index >= self.size()) {
281+
} else if (index >= self.size()) {
283282
throw py::index_error("");
284283
}
285284
return self.at(index);
@@ -300,13 +299,14 @@ void init_block(py::module m_parent)
300299
return Amulet::deserialise<Amulet::BlockStack>(state.cast<std::string>());
301300
}));
302301

303-
pyext::collections::def_Sequence_getitem_slice(BlockStack);
304-
pyext::collections::def_Sequence_contains(BlockStack);
305-
pyext::collections::def_Sequence_iter<Amulet::Block>(BlockStack);
306-
pyext::collections::def_Sequence_reversed<Amulet::Block>(BlockStack);
307-
pyext::collections::def_Sequence_index(BlockStack);
308-
pyext::collections::def_Sequence_count(BlockStack);
309-
pyext::collections::register_Sequence(BlockStack);
302+
using BlockSequence = pyext::collections::Sequence<Amulet::Block>;
303+
BlockSequence::def_getitem_slice(BlockStack);
304+
BlockSequence::def_contains(BlockStack);
305+
BlockSequence::def_iter(BlockStack);
306+
BlockSequence::def_reversed(BlockStack);
307+
BlockSequence::def_index(BlockStack);
308+
BlockSequence::def_count(BlockStack);
309+
BlockSequence::register_cls(BlockStack);
310310

311311
BlockStack.def(py::self == py::self);
312312
BlockStack.def(py::self > py::self);

src/amulet/core/block_entity/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class BlockEntity(amulet.core.version.PlatformVersionContainer):
1414
"""
1515

1616
@typing.overload
17-
def __eq__(self, arg0: BlockEntity) -> bool: ...
17+
def __eq__(self, other: BlockEntity) -> bool: ...
1818
@typing.overload
19-
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
19+
def __eq__(self, other: typing.Any) -> bool | types.NotImplementedType: ...
2020
def __hash__(self) -> int: ...
2121
def __init__(
2222
self,

src/amulet/core/chunk/component/section_array_map.py.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,18 @@ py::module init_section_array_map(py::module m_parent)
221221
SectionArrayMap.def(
222222
"__contains__",
223223
&Amulet::SectionArrayMap::contains_section);
224-
pyext::collections::def_Mapping_keys<std::int64_t>(SectionArrayMap);
225-
pyext::collections::def_Mapping_values<pyext::numpy::array_t<std::uint32_t>>(SectionArrayMap);
226-
pyext::collections::def_Mapping_items<std::int64_t, pyext::numpy::array_t<std::uint32_t>>(SectionArrayMap);
227-
pyext::collections::def_Mapping_get<std::int64_t, pyext::numpy::array_t<std::uint32_t>>(SectionArrayMap);
228-
pyext::collections::def_Mapping_eq(SectionArrayMap);
229-
pyext::collections::def_Mapping_hash(SectionArrayMap);
230-
pyext::collections::def_MutableMapping_pop<std::int64_t, pyext::numpy::array_t<std::uint32_t>>(SectionArrayMap);
231-
pyext::collections::def_MutableMapping_popitem<std::int64_t, pyext::numpy::array_t<std::uint32_t>>(SectionArrayMap);
232-
pyext::collections::def_MutableMapping_update(SectionArrayMap);
233-
pyext::collections::def_MutableMapping_setdefault<std::int64_t, pyext::numpy::array_t<std::uint32_t>>(SectionArrayMap);
234-
pyext::collections::register_MutableMapping(SectionArrayMap);
224+
using SectionMap = pyext::collections::MutableMapping<std::int64_t, pyext::numpy::array_t<std::uint32_t>>;
225+
SectionMap::def_keys(SectionArrayMap);
226+
SectionMap::def_values(SectionArrayMap);
227+
SectionMap::def_items(SectionArrayMap);
228+
SectionMap::def_get(SectionArrayMap);
229+
SectionMap::def_eq(SectionArrayMap);
230+
SectionMap::def_hash(SectionArrayMap);
231+
SectionMap::def_pop(SectionArrayMap);
232+
SectionMap::def_popitem(SectionArrayMap);
233+
SectionMap::def_update(SectionArrayMap);
234+
SectionMap::def_setdefault(SectionArrayMap);
235+
SectionMap::register_cls(SectionArrayMap);
235236

236237
SectionArrayMap.def(
237238
py::pickle(

src/amulet/core/chunk/component/section_array_map.pyi

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,69 @@ class SectionArrayMap:
4040

4141
def __contains__(self, arg0: typing.SupportsInt) -> bool: ...
4242
def __delitem__(self, arg0: typing.SupportsInt) -> None: ...
43-
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
43+
def __eq__(self, other: typing.Any) -> bool | types.NotImplementedType: ...
4444
def __getitem__(
4545
self, arg0: typing.SupportsInt
4646
) -> numpy.typing.NDArray[numpy.uint32]: ...
4747
def __hash__(self) -> int: ...
4848
def __init__(
4949
self,
5050
array_shape: tuple[typing.SupportsInt, typing.SupportsInt, typing.SupportsInt],
51-
default_array: (
52-
typing.SupportsInt
53-
| amulet.core.chunk.component.section_array_map.IndexArray3D
54-
| collections.abc.Buffer
55-
),
51+
default_array: typing.SupportsInt | IndexArray3D | collections.abc.Buffer,
5652
) -> None: ...
5753
def __iter__(self) -> collections.abc.Iterator[int]: ...
5854
def __len__(self) -> int: ...
5955
def __setitem__(
60-
self,
61-
arg0: typing.SupportsInt,
62-
arg1: (
63-
amulet.core.chunk.component.section_array_map.IndexArray3D
64-
| collections.abc.Buffer
65-
),
56+
self, arg0: typing.SupportsInt, arg1: IndexArray3D | collections.abc.Buffer
6657
) -> None: ...
58+
@typing.overload
6759
def get(
68-
self,
69-
key: typing.SupportsInt,
70-
default: numpy.typing.NDArray[numpy.uint32] | None = None,
60+
self, key: typing.SupportsInt
7161
) -> numpy.typing.NDArray[numpy.uint32] | None: ...
62+
@typing.overload
63+
def get(
64+
self, key: typing.SupportsInt, default: numpy.typing.NDArray[numpy.uint32]
65+
) -> numpy.typing.NDArray[numpy.uint32]: ...
66+
@typing.overload
67+
def get[T](
68+
self, key: typing.SupportsInt, default: T
69+
) -> numpy.typing.NDArray[numpy.uint32] | T: ...
7270
def items(
7371
self,
7472
) -> collections.abc.ItemsView[int, numpy.typing.NDArray[numpy.uint32]]: ...
7573
def keys(self) -> collections.abc.KeysView[int]: ...
74+
@typing.overload
75+
def pop(self, key: typing.SupportsInt) -> numpy.typing.NDArray[numpy.uint32]: ...
76+
@typing.overload
7677
def pop(
77-
self, key: typing.SupportsInt, default: numpy.typing.NDArray[numpy.uint32] = ...
78+
self, key: typing.SupportsInt, default: numpy.typing.NDArray[numpy.uint32]
7879
) -> numpy.typing.NDArray[numpy.uint32]: ...
80+
@typing.overload
81+
def pop[T](
82+
self, key: typing.SupportsInt, default: T
83+
) -> numpy.typing.NDArray[numpy.uint32] | T: ...
7984
def popitem(self) -> tuple[int, numpy.typing.NDArray[numpy.uint32]]: ...
8085
def populate(self, arg0: typing.SupportsInt) -> None: ...
86+
@typing.overload
8187
def setdefault(
82-
self, arg0: typing.SupportsInt, arg1: numpy.typing.NDArray[numpy.uint32] | None
83-
) -> numpy.typing.NDArray[numpy.uint32] | None: ...
84-
def update(self, other: typing.Any = (), **kwargs: typing.Any) -> None: ...
88+
self, key: typing.SupportsInt
89+
) -> numpy.typing.NDArray[numpy.uint32]: ...
90+
@typing.overload
91+
def setdefault(
92+
self, key: typing.SupportsInt, default: numpy.typing.NDArray[numpy.uint32]
93+
) -> numpy.typing.NDArray[numpy.uint32]: ...
94+
def update(
95+
self,
96+
other: (
97+
collections.abc.Mapping[
98+
typing.SupportsInt, numpy.typing.NDArray[numpy.uint32]
99+
]
100+
| collections.abc.Iterable[
101+
tuple[typing.SupportsInt, numpy.typing.NDArray[numpy.uint32]]
102+
]
103+
) = (),
104+
**kwargs: numpy.typing.NDArray[numpy.uint32],
105+
) -> None: ...
85106
def values(
86107
self,
87108
) -> collections.abc.ValuesView[numpy.typing.NDArray[numpy.uint32]]: ...
@@ -91,10 +112,5 @@ class SectionArrayMap:
91112
def default_array(self) -> int | numpy.ndarray: ...
92113
@default_array.setter
93114
def default_array(
94-
self,
95-
arg1: (
96-
typing.SupportsInt
97-
| amulet.core.chunk.component.section_array_map.IndexArray3D
98-
| collections.abc.Buffer
99-
),
115+
self, arg1: typing.SupportsInt | IndexArray3D | collections.abc.Buffer
100116
) -> None: ...

src/amulet/core/entity/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class Entity(amulet.core.version.PlatformVersionContainer):
1414
"""
1515

1616
@typing.overload
17-
def __eq__(self, arg0: Entity) -> bool: ...
17+
def __eq__(self, other: Entity) -> bool: ...
1818
@typing.overload
19-
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
19+
def __eq__(self, other: typing.Any) -> bool | types.NotImplementedType: ...
2020
def __hash__(self) -> int: ...
2121
def __init__(
2222
self,

src/amulet/core/palette/biome_palette.py.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void init_biome_palette(py::module biome_palette_module)
4848
bounds_check(self.size(), index);
4949
return self.index_to_biome(index);
5050
});
51-
pyext::collections::def_Sequence_getitem_slice(BiomePalette);
51+
5252
BiomePalette.def(
5353
"__contains__",
5454
[](const Amulet::BiomePalette& self, Py_ssize_t index) {
@@ -57,11 +57,13 @@ void init_biome_palette(py::module biome_palette_module)
5757
BiomePalette.def(
5858
"__contains__",
5959
&Amulet::BiomePalette::contains_biome);
60-
pyext::collections::def_Sequence_iter(BiomePalette);
61-
pyext::collections::def_Sequence_reversed(BiomePalette);
62-
pyext::collections::def_Sequence_index(BiomePalette);
63-
pyext::collections::def_Sequence_count(BiomePalette);
64-
pyext::collections::register_Sequence(BiomePalette);
60+
using BiomeSequence = pyext::collections::Sequence<Amulet::Biome>;
61+
BiomeSequence::def_getitem_slice(BiomePalette);
62+
BiomeSequence::def_iter(BiomePalette);
63+
BiomeSequence::def_reversed(BiomePalette);
64+
BiomeSequence::def_index(BiomePalette);
65+
BiomeSequence::def_count(BiomePalette);
66+
BiomeSequence::register_cls(BiomePalette);
6567

6668
BiomePalette.def(
6769
"index_to_biome",

src/amulet/core/palette/biome_palette.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class BiomePalette(amulet.core.version.VersionRangeContainer):
1616
@typing.overload
1717
def __getitem__(self, arg0: typing.SupportsInt) -> amulet.core.biome.Biome: ...
1818
@typing.overload
19-
def __getitem__(self, arg0: slice) -> list: ...
19+
def __getitem__(self, item: slice) -> list[amulet.core.biome.Biome]: ...
2020
def __init__(self, arg0: amulet.core.version.VersionRange) -> None: ...
21-
def __iter__(self) -> collections.abc.Iterator[typing.Any]: ...
21+
def __iter__(self) -> collections.abc.Iterator[amulet.core.biome.Biome]: ...
2222
def __len__(self) -> int: ...
2323
def __repr__(self) -> str: ...
24-
def __reversed__(self) -> collections.abc.Iterator[typing.Any]: ...
24+
def __reversed__(self) -> collections.abc.Iterator[amulet.core.biome.Biome]: ...
2525
def biome_to_index(self, arg0: amulet.core.biome.Biome) -> int:
2626
"""
2727
Get the index of the biome in the palette.
@@ -31,10 +31,10 @@ class BiomePalette(amulet.core.version.VersionRangeContainer):
3131
:return: The index of the biome in the palette.
3232
"""
3333

34-
def count(self, value: typing.Any) -> int: ...
34+
def count(self, value: amulet.core.biome.Biome) -> int: ...
3535
def index(
3636
self,
37-
value: typing.Any,
37+
value: amulet.core.biome.Biome,
3838
start: typing.SupportsInt = 0,
3939
stop: typing.SupportsInt = 9223372036854775807,
4040
) -> int: ...

src/amulet/core/palette/block_palette.py.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void init_block_palette(py::module block_palette_module)
4848
bounds_check(self.size(), index);
4949
return self.index_to_block_stack(index);
5050
});
51-
pyext::collections::def_Sequence_getitem_slice(BlockPalette);
51+
5252
BlockPalette.def(
5353
"__contains__",
5454
[](const Amulet::BlockPalette& self, Py_ssize_t index) {
@@ -57,11 +57,13 @@ void init_block_palette(py::module block_palette_module)
5757
BlockPalette.def(
5858
"__contains__",
5959
&Amulet::BlockPalette::contains_block);
60-
pyext::collections::def_Sequence_iter<Amulet::BlockStack>(BlockPalette);
61-
pyext::collections::def_Sequence_reversed<Amulet::BlockStack>(BlockPalette);
62-
pyext::collections::def_Sequence_index(BlockPalette);
63-
pyext::collections::def_Sequence_count(BlockPalette);
64-
pyext::collections::register_Sequence(BlockPalette);
60+
using BlockSequence = pyext::collections::Sequence<Amulet::BlockStack>;
61+
BlockSequence::def_getitem_slice(BlockPalette);
62+
BlockSequence::def_iter(BlockPalette);
63+
BlockSequence::def_reversed(BlockPalette);
64+
BlockSequence::def_index(BlockPalette);
65+
BlockSequence::def_count(BlockPalette);
66+
BlockSequence::register_cls(BlockPalette);
6567

6668
BlockPalette.def(
6769
"index_to_block_stack",

0 commit comments

Comments
 (0)