@@ -18,6 +18,35 @@ namespace pyunrealsdk::unreal {
18
18
19
19
namespace {
20
20
21
+ /* *
22
+ * @brief Throws a type error for missing required positional arguments.
23
+ *
24
+ * @param func_name The name of the function which was called.
25
+ * @param missing_required_args The names of the missing required args,
26
+ */
27
+ [[noreturn]] void throw_missing_required_args (FName func_name,
28
+ const std::vector<FName>& missing_required_args) {
29
+ auto num_missing = missing_required_args.size ();
30
+
31
+ std::ostringstream stream{};
32
+ stream << func_name << " () missing " << num_missing << " required positional argument" ;
33
+ if (num_missing > 1 ) {
34
+ stream << ' s' ;
35
+ }
36
+ stream << " : " ;
37
+
38
+ for (size_t i = 0 ; i < num_missing - 1 ; i++) {
39
+ stream << ' \' ' << missing_required_args[i] << " ', " ;
40
+ }
41
+ if (num_missing > 1 ) {
42
+ stream << " and " ;
43
+ }
44
+
45
+ stream << ' \' ' << missing_required_args.back () << ' \' ' ;
46
+
47
+ throw py::type_error (stream.str ());
48
+ }
49
+
21
50
/* *
22
51
* @brief Fills the params struct for a function with args from python.
23
52
* @note While this is similar to `make_struct`, we need to do some extra processing on the params,
@@ -86,16 +115,7 @@ std::pair<UProperty*, std::vector<UProperty*>> fill_py_params(WrappedStruct& par
86
115
}
87
116
88
117
if (!missing_required_args.empty ()) {
89
- std::ostringstream stream{};
90
- stream << params.type ->Name << " () missing " << missing_required_args.size ()
91
- << " required positional arguments: " ;
92
-
93
- for (size_t i = 0 ; i < missing_required_args.size () - 1 ; i++) {
94
- stream << ' \' ' << missing_required_args[i] << " ', " ;
95
- }
96
- stream << " and '" << missing_required_args.back () << ' \' ' ;
97
-
98
- throw py::type_error (stream.str ());
118
+ throw_missing_required_args (params.type ->Name , missing_required_args);
99
119
}
100
120
101
121
if (!kwargs.empty ()) {
0 commit comments