Skip to content

Commit b3879f9

Browse files
Improve type of function callbacks in register_upgrade_function and register_downgrade_function (#1445)
1 parent 2e53169 commit b3879f9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/py-opentimelineio/opentimelineio-bindings/otio_bindings.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright Contributors to the OpenTimelineIO project
33

44
#include <pybind11/pybind11.h>
5+
#include <pybind11/functional.h>
56
#include "otio_anyDictionary.h"
67
#include "otio_anyVector.h"
78
#include "otio_bindings.h"
@@ -71,13 +72,12 @@ static void register_python_type(py::object class_object,
7172

7273
static bool register_upgrade_function(std::string const& schema_name,
7374
int version_to_upgrade_to,
74-
py::object const& upgrade_function_obj) {
75+
std::function<void(AnyDictionaryProxy*)> const& upgrade_function_obj) {
7576
std::function<void (AnyDictionary* d)> upgrade_function = [upgrade_function_obj](AnyDictionary* d) {
7677
py::gil_scoped_acquire acquire;
7778

7879
auto ptr = d->get_or_create_mutation_stamp();
79-
py::object dobj = py::cast((AnyDictionaryProxy*)ptr);
80-
upgrade_function_obj(dobj);
80+
upgrade_function_obj((AnyDictionaryProxy*)ptr);
8181
};
8282

8383
// further discussion required about preventing double registering
@@ -112,16 +112,15 @@ static bool
112112
register_downgrade_function(
113113
std::string const& schema_name,
114114
int version_to_downgrade_from,
115-
py::object const& downgrade_function_obj)
115+
std::function<void(AnyDictionaryProxy*)> const& downgrade_function_obj)
116116
{
117117
std::function<void (AnyDictionary* d)> downgrade_function = (
118118
[downgrade_function_obj](AnyDictionary* d)
119119
{
120120
py::gil_scoped_acquire acquire;
121121

122122
auto ptr = d->get_or_create_mutation_stamp();
123-
py::object dobj = py::cast((AnyDictionaryProxy*)ptr);
124-
downgrade_function_obj(dobj);
123+
downgrade_function_obj((AnyDictionaryProxy*)ptr);
125124
}
126125
);
127126

0 commit comments

Comments
 (0)