-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Decode bytes to strings in Python Object API #8551
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
base: master
Are you sure you want to change the base?
Decode bytes to strings in Python Object API #8551
Conversation
Bump |
@aardappel bump, can we get the CI run on this PR? |
You can get the CI to run by rebasing, it is out of date.. I guess I'll do that for you. |
@@ -132,6 +132,8 @@ def _UnPack(self, nestedUnionTest): | |||
if nestedUnionTest is None: | |||
return | |||
self.name = nestedUnionTest.Name() | |||
if self.name is not None: | |||
self.name = self.name.decode('utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be self.name = nestedUnionTest.name.decode('utf-8')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nestedUnionTest
is not an object API type, so the only way to access the name from that object is via nestedUnionTest.Name()
.
This change is intentional, but if you're asking for a modification to the auto-generated code, I could change the autogeneration here to be
code += GetIndents(3) + "self." + field_field + " = " + struct_var + "." + field_method + "().decode('utf-8')";
Then this would read
self.name = nestedUnionTest.Name()
if self.name is not None:
self.name = nestedUnionTest.Name().decode('utf-8')
It's functionally the same, though, since self.name
is set to nestedUnionTest.name()
a couple lines beforehand. I personally think the current implementation is a bit more readable, but I'm open to suggestions.
Looks ok, I guess? @dbaileychess |
Bump @aardappel and @dbaileychess |
Type-hints for the Python Object API are incorrect for strings - the
_UnPack()
method does not convert bytes to strings. This PR introduces an optional flag (false by default) that enables decoding the bytes into string objects.Resolves #5997