-
Notifications
You must be signed in to change notification settings - Fork 234
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
Add type checking to strings/bytes for Python/Ruby #1597
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ namespace uniffi_type_limits { | |
f64 take_f64(f64 v); | ||
|
||
string take_string(string v); | ||
bytes take_bytes(bytes v); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,9 @@ def read(buf): | |
|
||
@staticmethod | ||
def write(value, buf): | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, basically that.
Because I'm trying to mirror Python's native semantics here. Take e.g. the |
||
memoryview(value) | ||
except TypeError: | ||
raise TypeError("a bytes-like object is required, not {!r}".format(type(value).__name__)) | ||
buf.writeI32(len(value)) | ||
buf.write(value) |
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.
It's not clear to me what the current semantics are - does this work without this patch? If so, what's the motivation for preventing this from working?
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.
(I mean, I guess "does the object allow
str(ob)
?" isn't really a great indicator of "this object wants to be seen as string like", but my question is really more about "do we want to exclude objects which want to be string like?"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.
I didn't change the current semantics except for throwing
TypeError
instead ofAttributeError
. So no, it does not work without this patch.In this way, this test is trying to test for the current behavior.