Skip to content

Commit 8198c19

Browse files
authored
Merge pull request #65 from apple1417/master
add copy methods to wrapped struct
2 parents 1e8a4cb + 0e35545 commit 8198c19

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Upcoming
4+
5+
- `WrappedStruct` now supports being copied via the `copy` module.
6+
7+
[2ce96e52](https://github.com/bl-sdk/pyunrealsdk/commit/2ce96e52)
8+
39
## v1.5.2
410

511
### unrealsdk v1.6.1

src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,22 @@ void register_wrapped_struct(py::module_& mod) {
212212
" field: The field to set.\n"
213213
" value: The value to write.",
214214
"field"_a, "value"_a)
215+
.def(
216+
"__copy__", [](const WrappedStruct& self) { return WrappedStruct(self); },
217+
"Creates a copy of this struct. Don't call this directly, use copy.copy().\n"
218+
"\n"
219+
"Returns:\n"
220+
" A new, python-owned copy of this struct.")
221+
.def(
222+
"__deepcopy__",
223+
[](const WrappedStruct& self, const py::dict& /*memo*/) { return WrappedStruct(self); },
224+
"Creates a copy of this struct. Don't call this directly, use copy.deepcopy().\n"
225+
"\n"
226+
"Args:\n"
227+
" memo: Opaque dict used by deepcopy internals."
228+
"Returns:\n"
229+
" A new, python-owned copy of this struct.",
230+
"memo"_a)
215231
.def_readwrite("_type", &WrappedStruct::type);
216232
}
217233

stubs/unrealsdk/unreal/_wrapped_struct.pyi

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ from ._uobject_children import UField, UFunction, UScriptStruct, UStruct
77
class WrappedStruct:
88
_type: UStruct
99

10+
def __copy__(self) -> WrappedStruct:
11+
"""
12+
Creates a copy of this struct. Don't call this directly, use copy.copy().
13+
14+
Returns:
15+
A new, python-owned copy of this struct.
16+
"""
17+
18+
def __deepcopy__(self, memo: dict[Any, Any]) -> WrappedStruct:
19+
"""
20+
Creates a copy of this struct. Don't call this directly, use copy.deepcopy().
21+
22+
Args:
23+
memo: Opaque dict used by deepcopy internal
24+
Returns:
25+
A new, python-owned copy of this struct.
26+
"""
27+
1028
def __dir__(self) -> list[str]:
1129
"""
1230
Gets the attributes which exist on this struct.

0 commit comments

Comments
 (0)