Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper - Explicit config enable_stream(...) to have unique arg count (API CHANGE) #11861

Merged
merged 4 commits into from Jun 15, 2023

Conversation

Nir-Az
Copy link
Collaborator

@Nir-Az Nir-Az commented Jun 1, 2023

Python cannot distinguish between enums, all enums are treated as ints.
So we cannot have 2 similar functions with the same arg count that only change the enum type.

This PR enforce no default arguments in enable_stream() functions (luckily we have only unique counts on those)

@Nir-Az Nir-Az requested a review from maloel June 1, 2023 08:54
@Nir-Az Nir-Az changed the title Explicit config enable_stream(...) to have unique arg count Python wrapper - Explicit config enable_stream(...) to have unique arg count (API CHANGE) Jun 1, 2023
@maloel
Copy link
Collaborator

maloel commented Jun 1, 2023

I think one of our examples has one call with only one argument... have you checked?

@Nir-Az
Copy link
Collaborator Author

Nir-Az commented Jun 1, 2023

I think one of our examples has one call with only one argument... have you checked?

Missed that one, fixed

@@ -18,7 +18,7 @@
pipe = rs.pipeline()
config = rs.config()
# Enable depth stream
config.enable_stream(rs.stream.depth)
config.enable_stream(rs.stream.depth, rs.format.z16, 30)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old version was the one that was (stream_type,stream_index=-1), right? This is another version of enable_stream, right? Is it equivalent? Just want to make sure...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct this use "stream_type"_a, "format"_a, "framerate"_a)

I will also run the example before merging it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified
image

I wonder if we should add a python only 1 argument function.
stream type only.
Normally the user doesn't care about stream index.
Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an option, if we want better backwards compatibility. (and usage, I guess)
Should I wait before approving, then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it

@Nir-Az Nir-Az requested a review from maloel June 14, 2023 07:58
@@ -48,6 +48,9 @@ void init_pipeline(py::module &m) {
"Upon calling resolve(), the config checks for conflicts between the application configuration requests and the attached computer vision "
"modules and processing blocks requirements, and fails if conflicts are found.\n"
"Before resolve() is called, no conflict check is done.", "stream_type"_a, "stream_index"_a, "width"_a, "height"_a, "format"_a, "framerate"_a)


.def("enable_stream", []( rs2::config* c, rs2_stream s ) -> void { return c->enable_stream( s, -1 ); }, "Stream type only. Other parameters are resolved internally.", "stream_type"_a )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the explicit -1 instead of using the C++ enable_stream that takes only 1 arg? (i.e., it has a default second arg)

Copy link
Collaborator

@maloel maloel Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it can be:

.def("enable_stream", (void (rs2::config::*)(rs2_stream)) &rs2::config::enable_stream, ...)

No? Not sure it'll work -- but if not, then just remove the explicit -1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be yes, I wanted to show that I explicitly call this command arguments but without it it will also work the same.
Do you think it's preferred?

Copy link
Collaborator

@maloel maloel Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I don't like is the explicit -1, because it presumes to know what the default is. Up to you how to do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@Nir-Az Nir-Az merged commit cb1aae5 into IntelRealSense:development Jun 15, 2023
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants