Skip to content

Commit 5faf124

Browse files
Replace py::object type by optional<std::string> for name parameters (#1446)
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent 33b98d4 commit 5faf124

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ using TrackVectorProxy =
4949
using SOWithMetadata = SerializableObjectWithMetadata;
5050

5151
namespace {
52-
const std::string string_or_none_converter(py::object& thing) {
53-
if (thing.is(py::none())) {
54-
return std::string();
55-
}
56-
else {
57-
return py::str(thing);
58-
}
59-
}
6052

6153
template<typename T, typename U>
6254
bool children_if(T* t, py::object descended_from_type, optional<TimeRange> const& search_range, bool shallow_search, std::vector<SerializableObject*>& l) {
@@ -210,12 +202,12 @@ A marker indicates a marked range of time on an item in a timeline, usually with
210202
The marked range may have a zero duration. The marked range is in the owning item's time coordinate system.
211203
)docstring")
212204
.def(py::init([](
213-
py::object name,
205+
optional<std::string> name,
214206
TimeRange marked_range,
215207
std::string const& color,
216208
py::object metadata) {
217209
return new Marker(
218-
string_or_none_converter(name),
210+
name.value_or(""),
219211
marked_range,
220212
color,
221213
py_to_any_dictionary(metadata));
@@ -551,12 +543,12 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
551543
.value("never", Track::NeighborGapPolicy::never);
552544

553545
track_class
554-
.def(py::init([](py::object name, py::object children,
546+
.def(py::init([](optional<std::string> name, py::object children,
555547
optional<TimeRange> const& source_range,
556548
std::string const& kind, py::object metadata) {
557549
auto composable_children = py_to_vector<Composable*>(children);
558550
Track* t = new Track(
559-
string_or_none_converter(name),
551+
name.value_or(""),
560552
source_range,
561553
kind,
562554
py_to_any_dictionary(metadata)
@@ -585,15 +577,15 @@ Should be subclassed (for example by :class:`.Track` and :class:`.Stack`), not u
585577

586578

587579
py::class_<Stack, Composition, managing_ptr<Stack>>(m, "Stack", py::dynamic_attr())
588-
.def(py::init([](py::object name,
580+
.def(py::init([](optional<std::string> name,
589581
py::object children,
590582
optional<TimeRange> const& source_range,
591583
py::object markers,
592584
py::object effects,
593585
py::object metadata) {
594586
auto composable_children = py_to_vector<Composable*>(children);
595587
Stack* s = new Stack(
596-
string_or_none_converter(name),
588+
name.value_or(""),
597589
source_range,
598590
py_to_any_dictionary(metadata),
599591
py_to_vector<Effect*>(effects),
@@ -742,12 +734,12 @@ Represents media for which a concrete reference is missing.
742734
Note that a :class:`~MissingReference` may have useful metadata, even if the location of the media is not known.
743735
)docstring")
744736
.def(py::init([](
745-
py::object name,
737+
optional<std::string> name,
746738
optional<TimeRange> available_range,
747739
py::object metadata,
748740
optional<Imath::Box2d> const& available_image_bounds) {
749741
return new MissingReference(
750-
string_or_none_converter(name),
742+
name.value_or(""),
751743
available_range,
752744
py_to_any_dictionary(metadata),
753745
available_image_bounds);

0 commit comments

Comments
 (0)